You should first need to now "why" then you should go to "how"

"Why" we need this? i.e. creating a class which cannot be instantiated by
the end user but can be instantiated by some other class
-----
As Jamie described in its earlier post there are scenarios where we require
this type of functionality that some class must NOT be initialized by the
end user of our class. For example in this scenario that creating a DataRow
in "air" does NOT make any sense because columns are necessary parameter.
Which are obviously part of DataTable class. Thats why DataTable actually
initializes the DataRow supplying the necessary parameters defined in
DataTable.

"How" we can achieve this?
------
This can be achieved by defining the class constructor with access
modifier "internal" for C# or "Friend" for VB. In this way this constructor
can only be called by the same assembly's classes. The external assembly
cannot access it.

On Mon, Mar 8, 2010 at 11:10 PM, crazy <[email protected]> wrote:

> ok.. then how can i create a class which will not allow to create objects
> itself and another class allowing it to create object.
> If possible,I would like to know the class architeture using in .net behind
> this concept...
> ( I am doing some R&D in .Net class architecture)
>
> Thanks
> Vipin
>
> On Mon, Mar 8, 2010 at 3:04 PM, Jamie Fraser <[email protected]>wrote:
>
>> Think of the DataTable in this case as being a pseudo-factory that is
>> responsible for creating DataRows.
>>
>> In a semantic sense, a datarow MUST have an associated table (to begin
>> with) - a row cannot exist without a table.
>>
>>
>> On Fri, Mar 5, 2010 at 9:00 PM, crazy <[email protected]> wrote:
>>
>>>  hi All,
>>>
>>> DataTable oDT=new DataTable();
>>>
>>> DataRowoDR=null;
>>>
>>> Case 1:
>>> oDR=new DataRow() ;
>>>
>>> Case 2:
>>> oDR=new oDT.DataRow();
>>>
>>>
>>> why Case 1 showing error?
>>> .Net doesnt allowing to create a object to that DataRow() class.But it
>>> allowing DataTable to create a object to DataRow().
>>> If so , what type of class is DataRow()?
>>>
>>> One scenario is there, if DataRow() class contains only private
>>> Constructor s and it contains a public static method which will create a new
>>> row . But in Datarow ,using Wincv I have checked available public methods ,
>>> but i cant able to find such a public static method in DataRow().
>>>
>>> Then  what type of architecture using  in DataRow() ?
>>>
>>>
>>>
>>>
>>> --
>>> "People who never make mistakes, never do anything."
>>>
>>> dEv
>>>
>>
>>
>
>
> --
> "People who never make mistakes, never do anything."
>
> dEv
>

Reply via email to