Click here to Skip to main content
15,929,253 members
Home / Discussions / C#
   

C#

 
AnswerRe: C++ to C# conversion? Pin
Zibar14-Dec-02 21:08
sussZibar14-Dec-02 21:08 
QuestionPossible to return null from constructor? Pin
leppie14-Dec-02 5:17
leppie14-Dec-02 5:17 
AnswerRe: Possible to return null from constructor? Pin
David Stone14-Dec-02 5:41
sitebuilderDavid Stone14-Dec-02 5:41 
AnswerRe: Possible to return null from constructor? Pin
James T. Johnson14-Dec-02 5:53
James T. Johnson14-Dec-02 5:53 
GeneralRe: Possible to return null from constructor? Pin
leppie14-Dec-02 6:11
leppie14-Dec-02 6:11 
GeneralRe: Possible to return null from constructor? Pin
Rob Graham14-Dec-02 6:27
Rob Graham14-Dec-02 6:27 
GeneralRe: Possible to return null from constructor? Pin
leppie14-Dec-02 6:43
leppie14-Dec-02 6:43 
GeneralRe: Possible to return null from constructor? Pin
Rob Graham14-Dec-02 7:38
Rob Graham14-Dec-02 7:38 
My example was flawed anyway.
This is better:
namespace FactoryTest
{
	/// <summary>
	/// Summary description for Factory.
	/// </summary>
	public  class Factory
	{
		// private constructor, only static methods...
		private Factory()
		{
		}
		public static FactoryObj Makeobj()
		{
			FactoryObj fObj = null;
			fObj = new FactoryObj();
			return fObj;
		}
		public class FactoryObj
		{
			// 'internal protected' constructor so only containing class can instantiate
			internal protected FactoryObj()
			{
				// constructor logic, could include try/catch so can't throw
				// exception
			}
			// public properties and methods...
			public int One
			{
				get {return	1;}
			}
			public void DoNothing ()
			{}
		}
	}
	public class TestIt
	{
		public TestIt()
		{
		}
		public void t1()
		{
			Factory.FactoryObj Obj = Factory.Makeobj();
			Obj.DoNothing();
			int one = Obj.One;
		}
	}
}


The protected internal makes the class creatable only by the containing factory, but the class is otherwise public.

You might consider defining an interface rather than a base class, and using the factory to return return instances of the interface.. probably still not helpful if you want external users to be able to implement classed that implement the interface...they would have to subclass the factory...
Smile | :)
GeneralRe: Possible to return null from constructor? Pin
leppie14-Dec-02 8:20
leppie14-Dec-02 8:20 
GeneralRichEdit control, bitmaps and number of lines Pin
peter271314-Dec-02 2:25
peter271314-Dec-02 2:25 
GeneralInterop problem Pin
Christian Graus13-Dec-02 22:58
protectorChristian Graus13-Dec-02 22:58 
GeneralRe: Interop problem Pin
James T. Johnson14-Dec-02 0:25
James T. Johnson14-Dec-02 0:25 
GeneralRe: Interop problem Pin
Christian Graus14-Dec-02 9:48
protectorChristian Graus14-Dec-02 9:48 
GeneralEnter key pressed in a VS.NET addin control Pin
Nathan Tran13-Dec-02 20:18
Nathan Tran13-Dec-02 20:18 
GeneralRe: Enter key pressed in a VS.NET addin control Pin
Nathan Tran13-Dec-02 20:27
Nathan Tran13-Dec-02 20:27 
GeneralRe: Enter key pressed in a VS.NET addin control Pin
WizardOfPeyton6-Jan-03 9:48
WizardOfPeyton6-Jan-03 9:48 
Questiongive sample code plzz? Pin
imran_rafique13-Dec-02 9:24
imran_rafique13-Dec-02 9:24 
AnswerRe: give sample code plzz? Pin
Gaul13-Dec-02 13:08
Gaul13-Dec-02 13:08 
GeneralRe: give sample code plzz? Pin
imran_rafique14-Dec-02 10:29
imran_rafique14-Dec-02 10:29 
GeneralRe: give sample code plzz? Pin
imran_rafique15-Dec-02 2:33
imran_rafique15-Dec-02 2:33 
GeneralRe: give sample code plzz? Pin
Gaul15-Dec-02 3:15
Gaul15-Dec-02 3:15 
GeneralRe: give sample code plzz? Pin
imran_rafique15-Dec-02 9:52
imran_rafique15-Dec-02 9:52 
GeneralRe: give sample code plzz? Pin
Gaul16-Dec-02 4:45
Gaul16-Dec-02 4:45 
GeneralMultiline edit boxes: WantReturn Pin
Le centriste13-Dec-02 6:32
Le centriste13-Dec-02 6:32 
GeneralRe: Multiline edit boxes: WantReturn Pin
leppie13-Dec-02 6:49
leppie13-Dec-02 6:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.