473,385 Members | 1,587 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,385 software developers and data experts.

Business Object Advice, Nested Classes

I am architecting in a read only class for use in mapping data to a business
object. The object makes strong use of nested classes and their ability to
access protected fields. The downside is when a nested class inherits from
it’s parent class you get this infinite class chain in intellisense when
consuming the class. To get around this I created two child classes Reader
and Writer which require a base Person object.

When consuming the class you do:

Person.Reader person = Person.Reader.Load(“mike”); // Load a read only object
String name = person.Name;

Person.Writer person = Person.Writer.Load(“mike”); // Load a writable object
person.Name = “Mike”;
person.Save();

The biggest problem I have is trying to use nested classes to provide the
necessary protected access needed by the nested support classes like data
adapters. Some of the child classes such as the Writer should really inherit
from the Reader, which should just be the person, but when I do this I get
Person.Writer.Writer.Writer.Writer which is confusing when consuming. The
code below shows a workaround passing in the base Person to the Writer and
The Reader which I don’t like.

public class Person
{
protected string _name;

public class Reader
{
Reader(Person person)
{
this._person = person;
}
private Person _person;

public string Name
{
get { return this._person._name; }
}

public static Person.Reader Load(string name)
{
return new Reader(Adapter.Load(name));
}
}

public class Writer
{
Writer(Person person)
{
this._person = person;
}
private Person _person;

public string Name
{
get { return this._person._name; }
set { this._person._name = value; }
}

public static Person.Writer Load(string name)
{
return new Writer(Adapter.Load(name));
}
}

private class Adapter
{
public static Person Load(string name)
{
Person p = new Person();
p._name = name;
return p;
}
}
}
Jun 3 '06 #1
2 2349
miked wrote:
I am architecting in a read only class for use in mapping data to a
business object. The object makes strong use of nested classes and
their ability to access protected fields. The downside is when a
nested class inherits from it’s parent class you get this infinite
class chain in intellisense when consuming the class. To get around
this I created two child classes Reader and Writer which require a
base Person object.
I think you shouldn't use the design you have now. Nested classes
should be used in situations where you need a class type inside another
class, like a temp binding class in a form, which has no meaning
outside the containing class. Your usage of nested classes isn't doing
that.
When consuming the class you do:

Person.Reader person = Person.Reader.Load(“mike”); // Load a read
only object
String name = person.Name;

Person.Writer person = Person.Writer.Load(“mike”); // Load a
writable object
person.Name = “Mike”;
person.Save();
Excuse me if I miss something, but what do reader/writer thingies in a
readonly class?
The biggest problem I have is trying to use nested classes to provide
the necessary protected access needed by the nested support classes
like data adapters.


Isn't that because you're things way too difficult? I mean, the
load/save logic is INSIDE person, so that's all private to the class.
If person is readonly, you can only LOAD it. If it's not readonly, you
have no problems.

I was trying to rewrite your code below, but after a while I ended up
with a simple person class which had a load/save routine and a name
getter, as it's a readonly class.

So I think there's something mixed up in your problem: either it's not
a readonly class, and then there's no problem, or it is a readonly
class, and you can simply implement a load routine and a Name getter
and that's it.
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jun 4 '06 #2
You code does not show any inheritance though. Should the inheritance syntex
like:

public class Reader: Person

if you are doing inheritance?

But do read more on Interface, Abstract class, Virtual method before you do
further decision.

Have a read of the C# specification:
http://msdn.microsoft.com/netframewo...r/default.aspx

chanmm

"miked" <mi***@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
I am architecting in a read only class for use in mapping data to a
business
object. The object makes strong use of nested classes and their ability
to
access protected fields. The downside is when a nested class inherits
from
it's parent class you get this infinite class chain in intellisense when
consuming the class. To get around this I created two child classes
Reader
and Writer which require a base Person object.

When consuming the class you do:

Person.Reader person = Person.Reader.Load("mike"); // Load a read only
object
String name = person.Name;

Person.Writer person = Person.Writer.Load("mike"); // Load a writable
object
person.Name = "Mike";
person.Save();

The biggest problem I have is trying to use nested classes to provide the
necessary protected access needed by the nested support classes like data
adapters. Some of the child classes such as the Writer should really
inherit
from the Reader, which should just be the person, but when I do this I get
Person.Writer.Writer.Writer.Writer which is confusing when consuming. The
code below shows a workaround passing in the base Person to the Writer and
The Reader which I don't like.

public class Person
{
protected string _name;

public class Reader
{
Reader(Person person)
{
this._person = person;
}
private Person _person;

public string Name
{
get { return this._person._name; }
}

public static Person.Reader Load(string name)
{
return new Reader(Adapter.Load(name));
}
}

public class Writer
{
Writer(Person person)
{
this._person = person;
}
private Person _person;

public string Name
{
get { return this._person._name; }
set { this._person._name = value; }
}

public static Person.Writer Load(string name)
{
return new Writer(Adapter.Load(name));
}
}

private class Adapter
{
public static Person Load(string name)
{
Person p = new Person();
p._name = name;
return p;
}
}
}

Jun 4 '06 #3

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

Similar topics

6
by: Graham Pengelly | last post by:
Hi I'll try to spell out my problem as succinctly as possible... My database has a User table, an Organisation table, a Department table and a JobType table (amongst others) The...
8
by: ad | last post by:
I have studied buisness layer in http://beta.asp.net/QUICKSTART/util/srcview.aspx?path=~/aspnet/samples/data/GridViewObject.src It separate Author class to Author and AuthorComponent If I...
25
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business...
4
by: scottrm | last post by:
I am fairly new to oo design and I am looking at developing an object oriented asp.net application which will be built on top of a relational database. I have read quite a bit of the theory but...
18
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
1
by: Nemisis | last post by:
hi guys, Currently converting an old classic asp system to a OOP asp.net application. We are building the new application using a 3 tier arcitecture and i was wondering about the following. ...
25
by: Penelope Dramas | last post by:
Hello, I'm in a front of very serious .net redesign/rewrite of an old VB6 application. I had been asked to make it .NET 2.0 and would like to ask couple of questions regarding data access as...
8
by: morleyc | last post by:
Hi, until recently i was quite happy to add data sources from mssql database in visual studio and drag the datasets directly onto the form this creating a directly editable form which worked well....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...

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.