laubrass
asked on
Which is the best implement?!?
Hi Experts,
we use Singletons in some classes of our application.
here an example...
-------------------------- ---------- ---------- ---------- ---
class name: Features
-------------------------- ---------- ---------- ---------- ---
private string _Something;
public string Something
{
Get { return(_Something); }
Set { _Something = value; }
}
private static Features instance = null;
public static Features GetInstance()
{
if(instance == null)
{
instance = new ExportContoller();
}
return instance;
}
private Features()
{
}
(...)
-------------------------- ---------- ---------- ---------- ---
and i'm asking myself which call method do i have to use... i mean which is the best one!?!?!
Method 1:
Features keyID = Features.getInstance();
keyID.Something = "AGAH876876";
or
Method 2:
Features.getInstance().Som ething = "AGAH876876";
Does they have different Lifetime?!?
thks!
laubrass
we use Singletons in some classes of our application.
here an example...
--------------------------
class name: Features
--------------------------
private string _Something;
public string Something
{
Get { return(_Something); }
Set { _Something = value; }
}
private static Features instance = null;
public static Features GetInstance()
{
if(instance == null)
{
instance = new ExportContoller();
}
return instance;
}
private Features()
{
}
(...)
--------------------------
and i'm asking myself which call method do i have to use... i mean which is the best one!?!?!
Method 1:
Features keyID = Features.getInstance();
keyID.Something = "AGAH876876";
or
Method 2:
Features.getInstance().Som
Does they have different Lifetime?!?
thks!
laubrass
At first glance, the two calls appear identical to me, because Features.instance is static.
I believe both calls are identical and are compiled into same code.
The only iisue I can see from the above code is:
instance = new ExportContoller();
'instance' is of type 'Features'. Why's that?
The only iisue I can see from the above code is:
instance = new ExportContoller();
'instance' is of type 'Features'. Why's that?
ASKER
ExportContoller is a copy and paste error while posting.
It should ha been
instance = new Features();
It should ha been
instance = new Features();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.