restrict class to create object

Posted by Ajay.Kalol under ASP.NET on 9/13/2012 | Points: 10 | Views : 926 | Status : [Member] | Replies : 3
i have a Code structure like below :

namespace Same
{
public class A
{
public string Name{get;set;}
public B email{get;set;}
}

public class B
{
public string Email{get;set;}
}
}


I need to allow only class A to create object but want to restrict Class B to create Object.

If have any solution then plz suggest me..

Thanks.

Ajay
ajaypatelfromsanthal.blogspot.in



Responses

Posted by: Tanujad on: 9/13/2012 [Member] Starter | Points: 25

Up
0
Down
In order to restrict the object creation of a class, define that class as either static or abstract

public static class B

{
public string Email{get;set;}
}


when defined as static you cannot create an object, but you can access the method with the help of class name which is not the case when using abstract.


Thanks
Tanuja

Thanks
Tanuja
(If this content helped you, Please mark it as Answer)

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 9/14/2012 [Member] Starter | Points: 25

Up
0
Down
Right bu I have more than one class like Class B

Ajay
ajaypatelfromsanthal.blogspot.in

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/14/2012 [Member] Starter | Points: 25

Up
0
Down
Nice Explanation Tanuja.

Thanks & Regards
Hari

Ajay.Kalol, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response