Scope, Classes and Properties

  • Thread starter Thread starter paul perrin
  • Start date Start date
P

paul perrin

I have a class I want to implement in VB.Net - but can't get the behaviour I
want.

There are two issues - one how should I be getting the behaviour I want, and
second is there a better way altogether?

1) How do I...
I have two classes, one represents a 'data record', the other is a generic
'data field'.

The data-field class has properties defining the position and datatype etc
of a datafield. It also provides a property that is intended to return the
value of that datafield from the data-record.

The data-record class has a property that acts a a buffer for a physical
data record, and a number of properties that are of type 'data-field' (as
described above).

ie (in pseudo code - to illustrate the idea)

class datarecord
private rec as xmldocument
public fld1 as datafield
public fld2 as datafield
end class

class datafield
public fieldtype as string
public fieldpath as string
public function value()
return <<parent>>.rec.selectsinglenode(fieldpath)
end function
end class

So I really want the xmldocument (rec) in an instance of the datarecord
class to be accessible to datafields of that class.The problems I have had
include - if the xmldocument is shared as part of the datafield class then
all datafields share it (not just the ones attached to a particular
datarecord), if the datafield is made a private class of the datarecord then
its properties cannot be accessed by calling programs.

2) A better way?
The main purpose of all this is to give programmers simple access to XML
data that gets validated at compile time rather than run time - am I missing
a trick?

Regards

Paul Perrin
/)/+)
Immediate Data Ltd
 
No, the datafield can be made private to the dataRecord, and the datafield
are instantated inside datrecord class. You then need a property/methods to
enable you to read or set the values of the datafield inside the datarecord;
this way you can add validation etc

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
I can see that it could work that way, but it means that (pretty much) the
same code gets cut and pasted for each and every datafield in the datarecord
(datarecord.field1get, datarecordfield2get etc)

All datafields should share very similar behaviour, so if they can't be
implemented as a class then it suggests that there is 'something' missing
from the .net object architecture.

Could the main class (record) pass a function reference into the field
instance initialisation code, that the field could later call to fetch the
XMLdocument from its 'owning' record instance? (similar to delegates and
proxies).

In my original setup, I made the datafields public so they could have
various properties ('path' 'value' 'node') used in calling programs without
recoding them for every field.

Paul Perrin
/)/+)
Immediate Data Ltd


----- Original Message -----
From: "One Handed Man ( OHM - Terry Burns )" <news.microsoft.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Sunday, September 19, 2004 1:37 PM
Subject: Re: Scope, Classes and Properties
 
paul said:
I have a class I want to implement in VB.Net - but can't get the
behaviour I want.

There are two issues - one how should I be getting the behaviour I
want, and second is there a better way altogether?

1) How do I...
I have two classes, one represents a 'data record', the other is a
generic 'data field'.

The data-field class has properties defining the position and
datatype etc of a datafield. It also provides a property that is
intended to return the value of that datafield from the data-record.

The data-record class has a property that acts a a buffer for a
physical data record, and a number of properties that are of type
'data-field' (as described above).

ie (in pseudo code - to illustrate the idea)

class datarecord
private rec as xmldocument
public fld1 as datafield
public fld2 as datafield
end class

class datafield
public fieldtype as string
public fieldpath as string
public function value()
return <<parent>>.rec.selectsinglenode(fieldpath)
end function
end class

So I really want the xmldocument (rec) in an instance of the
datarecord class to be accessible to datafields of that class.The
problems I have had include - if the xmldocument is shared as part of
the datafield class then all datafields share it (not just the ones
attached to a particular datarecord), if the datafield is made a
private class of the datarecord then its properties cannot be
accessed by calling programs.

2) A better way?
The main purpose of all this is to give programmers simple access to
XML data that gets validated at compile time rather than run time -
am I missing a trick?

Regards

Paul Perrin
/)/+)
Immediate Data Ltd

Paul,

What if you change the constructor to the datafield class
so that it takes a reference to an xmldocument object?

Then if you want several datafield classes that belong
to a datarecord object to use the xmldocument object
of that datarecord object to access the values for the
datafields, you simply construct the datafield objects
to take the xmldocument object as an argument. Then
the datafield objects can access that particular
xmldocument object. And you don't have to make the
xmldocument object shared across *all* instances of
your datafield class.

I'm not sure if this answers your question - please
let me know if it doesn't.
 
Paul,

It is nice that you make your own compatible ADONET classes, however most
probably you have more result just using those.

Just my thought,

Cor
"paul perrin"
 
yes it would be a class and this can be instantiated inside the record
class.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Thanks - but as I read that, it would mean changes to the record document
would not be reflected in the fields.

My current solution is to define a delegate type in the field class, add a
'getDoc' function in the record class, and pass the (addressof) getDoc
function into the new method of the fields where is is stored in the
instance.

Then when the field is accessed it calls the delegate to fetch the XML from
the record instance it was created by and processes that.

Cheers

Paul Perrin
/)/+)
Immediate Data Ltd


----- Original Message -----
From: "Wild Wind" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Monday, September 20, 2004 12:54 AM
Subject: Re: Scope, Classes and Properties
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top