473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Scope, Classes and Properties

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
Nov 21 '05 #1
6 1418
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

"paul perrin" <pp**********@hotmail.com> wrote in message
news:ci**********@sparta.btinternet.com...
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

Nov 21 '05 #2
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

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

"paul perrin" <pp**********@hotmail.com> wrote in message
news:ci**********@sparta.btinternet.com...
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


Nov 21 '05 #3
paul perrin wrote:
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.

--
Akin

aknak at aksoto dot idps dot co dot uk
Nov 21 '05 #4
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"
Nov 21 '05 #5
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

"paul perrin" <pp**********@hotmail.com> wrote in message
news:ci**********@sparta.btinternet.com...
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

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

"paul perrin" <pp**********@hotmail.com> wrote in message
news:ci**********@sparta.btinternet.com...
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



Nov 21 '05 #6
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" <no****@blackhole.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Monday, September 20, 2004 12:54 AM
Subject: Re: Scope, Classes and Properties

paul perrin wrote:
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.

--
Akin

aknak at aksoto dot idps dot co dot uk

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aaronh64 | last post by:
Have you ever noticed that when you look at an Interface Class definition (ie IDisposable), the methods or properties belonging to the class are defined as abstract (C#) or overridable (vb)? How...
4
by: Marc Tanner | last post by:
Hello, I am currently working on a eventhandling system or something similar, and have the problem of loosing scope. I have read many interesting posts on this group and the faq article about...
3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
2
by: Don | last post by:
I'm asking this for a friend of mine, so forgive me if I'm getting some of the terminology wrong (I don't have any experience with ASP.NET). I've got an ASP application that has some classes that...
1
by: Rlrcstr | last post by:
Is there any way to restrain member visibility to within a class? I have a class with a few classes defined within. (Note that they aren't inheriting from the class, just encapsulated within it.) ...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
4
by: =?Utf-8?B?UmJydA==?= | last post by:
Sorry if this is a question that has been answered elsewhere. I did a search and didn't find the answer I am looking for. I am writing an ASP.NET app in VB.NET and am defining some classes in the...
3
by: Jeff | last post by:
I'm working my way through learning php, it looks a lot like perl and then again it doesn't. I'm confused about scope of variables and public. The PHP manual sometimes leaves me confused. I have...
3
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... At least by the group title, this seems like a question for dotnet.framework.aspnet.caching but that group seems pretty slow. I'm trying to sort things out with a co-worker. We've got...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.