OOP Question about .NET Framework

  • Thread starter Thread starter jmDesktop
  • Start date Start date
J

jmDesktop

In the .NET framework, how does one class "see" another class? For
example, in the DataTable class there is a method called NewRow(). It
returns an object type DataRow. But how does DataTable know about
DataRow? I guess this is more fundemental than .net. How does a
framework no about the objects inside of it?
 
It doesn't know what a NewRow() is until you attach it. If you look at the
code (in Lutz Roeder's Reflector), you see:

public DataRow NewRow()
{
DataRow row = this.NewRow(-1);
this.NewRowCreated(row);
return row;
}

This merely creates a row for that table. If this is strongly typed, it will
create the right type of row instead of a generic row like this. It knows
about the row when you add it:

internal void AddRow(DataRow row, int proposedID)
{
this.InsertRow(row, proposedID, -1);
}

Now, to the larger question. In general, your parent object has a collection
of children. In the DataTable, it has a RowCollection:

internal readonly DataRowCollection rowCollection;

rows are added to this collection. If you create an object, let's say a user
object that can have multiple addresses:

public class User
{
private AddressCollection addresses;
}

The address collection is like:

public class AddressCollection() : List<Address>
{
}

This is a very simple example, but it shows one way of linking things
together.

Back to "how does one object see another" it is through code.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
 
In the .NET framework, how does one class "see" another class? For
example, in the DataTable class there is a method called NewRow(). It
returns an object type DataRow. But how does DataTable know about
DataRow? I guess this is more fundemental than .net. How does a
framework no about the objects inside of it?

Any class can "see" any other classes that are in scope. Those other
classes might be Public classes on other assemblies to which the
current project has a reference, they might be Friend or Public
classes in the same project, or they might be Private classes
contained in the class.

DataTable only "knows" about DataRow because there is code in
DataTable that uses DataRow. The designer of the DataTable class
decided that the class that is used to represent rows in the DataTable
is DataRow, and coded accordingly, including defining the NewRow
method as:
Public Function NewRow As DataRow
 
Back
Top