473,769 Members | 7,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OOP question --- theoretically speaking....

Hello All,

I've decided that this OOP thing is not just a fad. With
that in mind, I'm desparately trying to get rid of my
function-oriented design paradigm and switch to a more
object-centric view of the world. Migrating some aspects
of my antiquated style has been straight-forward. For example:

I used to do this:

<old style>------------------------

public class Widget()
{
public string property1;
public string property2;
}

.... Somewhere in a "Datahandle r" class:

public Widget fetchWidget(int widgetid)
{
Widget w = new Widget();
.... do some database spelunking...

w.property1=... .
w.property2=... .

return w;
}
</old style>---------------------------

But now I do this

<new style>----------------------------

public class Widget()
{
private string _property1;
{
set
{ ... etc.

private string _property2;
{
set
{ ... etc.
public Widget(){}
public Widget(int widgetid)
{
this.fetchMe(wi dgetid);
}

private void fetchMe(int widgetid)
{
.... do some database spelunking...
.... poulate internal vars. ...

}
}
</new style>--------------------------
But what about collections of Widgets?

Continuing on from the first example above. In the same "Datahander s"
class, I used to have a method like:

<old style>---------------------------------------------------------

public ArrayList callingAllWidge ts()
{
ArrayList widgets = new ArrayList();
.... database spelunking....
foreach (whatever)
{
Widget w = new Widget();
w.property1=... etc.
...
widgets.Add(w);
}

return widgets;
}

</old style> -------------------------------------------------------

Obviously, there's no reason I couldn't use the same design using the
more updated version (the new style) of a widget, i.e:

public ArrayList callingAllWidge ts()
{
ArrayList widgets = new ArrayList();
.... database spelunking....
foreach (whatever)
{
Widget w = new Widget(foreachv alue);
widgets.Add(w);
}

return widgets;
}

but this seems like cheating ;) Is there a better, more universally
accepted superterrific way? Should i use a corresponding collections
class with an Indexer? Should I create some souped up IList
implemenation? I could certainly see the benefit of a class that
specialized in providing some aggregators (i.e. add all the Widgets
property1 values) but this isn't always necessary.

Thanks in advance..

Nov 17 '05 #1
9 1315
"See_Rock_C ity" <as**@asdf.co m> a écrit dans le message de news:
MP************* ***********@new s.giganews.com...
I've decided that this OOP thing is not just a fad.
Well it has stood the test of about 30 years :-))
<new style>----------------------------

public class Widget()
{
private string _property1;
{
set
{ ... etc.

private string _property2;
{
set
{ ... etc.
public Widget(){}
public Widget(int widgetid)
{
this.fetchMe(wi dgetid);
}

private void fetchMe(int widgetid)
{
.... do some database spelunking...
.... poulate internal vars. ...

}
}
</new style>--------------------------
There are some of us who feel that putting database code into a business
object is not really very OO. Doing this means that, should you change
database access components, you have to rewrite your class all over again.

It really is better and more beneficial to have a separate data layer that
knows how to read/write your objects (possibly using reflection), thereby
allowing you to program business objects without any knowledge of the
database you are using.
But what about collections of Widgets? Obviously, there's no reason I couldn't use the same design using the
more updated version (the new style) of a widget, i.e:

public ArrayList callingAllWidge ts()
{
ArrayList widgets = new ArrayList();
.... database spelunking....
foreach (whatever)
{
Widget w = new Widget(foreachv alue);
widgets.Add(w);
}

return widgets;
}

but this seems like cheating ;) Is there a better, more universally
accepted superterrific way? Should i use a corresponding collections
class with an Indexer? Should I create some souped up IList
implemenation? I could certainly see the benefit of a class that
specialized in providing some aggregators (i.e. add all the Widgets
property1 values) but this isn't always necessary.


You should never derive from or use ArrayList or any other general list
class. Instead you need to create typesafe list classes that only know how
to manipulate (e.g.) Widgets. Of course you would use something like
ArrayList inside this class but that is the only place you would have to
cast from object to Widget and back again.

The same principle appplies to lists as to single objects; try to separate
out the database code from the business concepts. But you would possibly
want to implement IList by delegation to the internal list to allow a data
mechanism to return/manipulate a common list type

A simplified mechanism to interface with databases (Object Persistence
Framework) would have an interface like this :

class ObjectBroker
{
bool StoreObject(obj ect obj);
bool DeleteObject(ob ject obj);
bool RetrieveObject( object obj);
IList RetrieveForType (Type type);
}

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #2
Joanna,

Well it has stood the test of about 30 years :-))


However almost the same time exist the so called relational databases which
for me seems to been build on punchcard methods and are unable in a one to
one way to hold a list structure. Something which was with databases before
that time very easy to do.

Therefore one of those is for me wrong. (My opinion the relational
database).

Just my thought,

Cor
Nov 17 '05 #3
In article <#p************ **@TK2MSFTNGP14 .phx.gbl>,
jo*****@nospamf orme.com says...
Hey Joanna, thanks for the reply!

<snip>

There are some of us who feel that putting database code into a business
object is not really very OO. Doing this means that, should you change
database access components, you have to rewrite your class all over again.

It really is better and more beneficial to have a separate data layer that
knows how to read/write your objects (possibly using reflection), thereby
allowing you to program business objects without any knowledge of the
database you are using.

This, I agree with completely. In fact, this was always a big question
in my mind. It doesn't feel right mixing the bl layer with the data
layer. I'm glad to hear you say this ;)

<snip>
You should never derive from or use ArrayList or any other general list
class.
By this I'm assuming you mean simply not to inherit from any intrinsic
collection implementation?
Instead you need to create typesafe list classes that only know how
to manipulate (e.g.) Widgets. Of course you would use something like
ArrayList inside this class but that is the only place you would have to
cast from object to Widget and back again.

The same principle appplies to lists as to single objects; try to separate
out the database code from the business concepts. But you would possibly
want to implement IList by delegation to the internal list to allow a data
mechanism to return/manipulate a common list type
I have (in the past) created classes that simply wrap a private
ArrayList and implement IList so that they are compatible with the
standard collections nomenclature calling clients would be used to.
This way, I can add class-specific methods blah blah blah.

A simplified mechanism to interface with databases (Object Persistence
Framework) would have an interface like this :

class ObjectBroker
{
bool StoreObject(obj ect obj);
bool DeleteObject(ob ject obj);
bool RetrieveObject( object obj);
IList RetrieveForType (Type type);
}
Ya' lost me here I'm embarrassed to say.
Joanna

--
Joanna Carter
Consultant Software Engineer

Nov 17 '05 #4
"See_Rock_C ity" <as**@asdf.co m> a écrit dans le message de news:
MP************* ***********@new s.giganews.com...
By this I'm assuming you mean simply not to inherit from any intrinsic
collection implementation?


Under .NET 1.1, you have to wrap a private list inside typesafe classes, but
in .NET 2.0, I use the generic List<T> types as they give me type safety for
zero coding effort :-))
class ObjectBroker
{
bool StoreObject(obj ect obj);
bool DeleteObject(ob ject obj);
bool RetrieveObject( object obj);
IList RetrieveForType (Type type);
}


Ya' lost me here I'm embarrassed to say.


Take a look at the articles on OPF on my site www.carterconsulting.org.uk

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #5
In message <#p************ **@TK2MSFTNGP14 .phx.gbl>, "Joanna Carter
(TeamB)" <jo*****@nospam forme.com> writes
There are some of us who feel that putting database code into a business
object is not really very OO. Doing this means that, should you change
database access components, you have to rewrite your class all over again.

It really is better and more beneficial to have a separate data layer that
knows how to read/write your objects (possibly using reflection), thereby
allowing you to program business objects without any knowledge of the
database you are using.


Hmm. I've always tried to make the database access tier independent of
the domain model; usually a matter of accepting simple types and
returning objects from the System.Data namespace. In my last job, we
initially hosted each tier as serviced components and serialised chunks
of the domain model out to the web UI layer via a service layer (kind of
a lazy memento pattern :o) ). The service layer included code for
mapping domain model objects to calls to database layer methods. Stuff
like:

class FooSL:ServicedC omponent
{
public Foo GetFoo(int id)
{
using(FooDB db = new FooDB())
{
DataTable dt = db.GetFooByID(i d);
DataRow row = dt.Rows[0];
int id = (int)row["id"];
string name = (string)row["name"];
return new Foo(id, name);
}
}
}

We eventually decided that we were tripping up too much over issues of
object identity, and were writing too much similar code, so I designed a
mapping infrastructure. This was the kind of thing you are talking
about; it made use of a few simple interfaces on classes in the domain
model, and an awful lot of reflection. Despite the often quoted advice
never to write your own object-relational mapping infrastructure, it
worked pretty well, and once people had got their heads round it, it
improved productivity. The important thing, I think, is that the logic
for creating objects and the logic for querying the database were
decoupled.

I've changed jobs since then, and the system I'm now responsible for is
much less transactional than those I used to build; write occasionally,
read frequently. I'm using a much simpler architecture, with all tiers
running in process with the web UI tier and the domain model directly
exposed to the UI code. No COM+ at all. It's simpler, faster, and easier
to update. I've still got a discrete data access tier, but it's
generally accessed from within domain model class constructors.

The point is, I'm now extending my work, which was largely to replace
the presentational side of the legacy system, with code to replace the
administrative tools, and I'm finding problems which would have been
easier to solve with a mapping architecture; issues like wanting to
update an object graph transactionally . I can live with domain model
classes containing dependencies upon the names of columns in datatables,
but passing SqlTransaction objects around is just a bit too icky.

So, I think I'm agreeing with you that some kind of mapper pattern is
desirable, but I'd want to separate the code which knows about the
persistent storage from the code which knows about the domain model.

Steve

--
Steve Walker
Nov 17 '05 #6
"Steve Walker" <st***@otolith. demon.co.uk> a écrit dans le message de news:
C7************* *@otolith.demon .co.uk...
I can live with domain model
classes containing dependencies upon the names of columns in datatables,
but passing SqlTransaction objects around is just a bit too icky.
That's one way of describing it :-))
So, I think I'm agreeing with you that some kind of mapper pattern is
desirable, but I'd want to separate the code which knows about the
persistent storage from the code which knows about the domain model.


I am in the middle of moving my Delphi OPF into C# 2.0. The code saving
using generics is absolutley mind-blowing. And finally I can use operator
overloading to give me a really simple syntax for concatenating Criteria for
submission to the OPF to retrieve lists, etc.

First create your Criteria :

SelectionCriter ion<int> age = new GreaterThanCrit erion<int>("Age ", 21);

SelectionCriter ion<string> name = new StartingCriteri on("Name", "Jo");

SelectionCriter ion<DateTime> startDate = new
GreaterThanOrEq ualToCriterion< DateTime>("Star tDate", DateTime.Now);

SelectionCriter ion allowance = new IsNullCriterion ("Allowance" );

....then concatenate them using expected logical operators :

SelectionCriter ion join = (age | name) & (startDate | allowance);

It just makes life so much easier not to have to think about DB related
stuff when you are designing systems.

Joanna

--
Joanna Carter
Consultant Software Engineer

Nov 17 '05 #7
"Steve Walker" <st***@otolith. demon.co.uk> a écrit dans le message de news:
C7************* *@otolith.demon .co.uk...
I can live with domain model
classes containing dependencies upon the names of columns in datatables,
but passing SqlTransaction objects around is just a bit too icky.
That's one way of describing it :-))
So, I think I'm agreeing with you that some kind of mapper pattern is
desirable, but I'd want to separate the code which knows about the
persistent storage from the code which knows about the domain model.


I am in the middle of moving my Delphi OPF into C# 2.0. The code saving
using generics is absolutley mind-blowing. And finally I can use operator
overloading to give me a really simple syntax for concatenating Criteria for
submission to the OPF to retrieve lists, etc.

First create your Criteria :

SelectionCriter ion<int> age = new GreaterThanCrit erion<int>("Age ", 21);

SelectionCriter ion<string> name = new StartingCriteri on("Name", "Jo");

SelectionCriter ion<DateTime> startDate = new
GreaterThanOrEq ualToCriterion< DateTime>("Star tDate", DateTime.Now);

SelectionCriter ion allowance = new IsNullCriterion ("Allowance" );

....then concatenate them using expected logical operators :

SelectionCriter ion join = (age | name) & (startDate | allowance);

It just makes life so much easier not to have to think about DB related
stuff when you are designing systems.

Joanna

--
Joanna Carter
Consultant Software Engineer

Nov 17 '05 #8
In message <#O************ **@tk2msftngp13 .phx.gbl>, "Joanna Carter
(TeamB)" <jo*****@nospam forme.com> writes
"Steve Walker" <st***@otolith. demon.co.uk> a écrit dans le message de news:
C7************ **@otolith.demo n.co.uk...
I can live with domain model
classes containing dependencies upon the names of columns in datatables,
but passing SqlTransaction objects around is just a bit too icky.
That's one way of describing it :-))


I was being polite :o)
So, I think I'm agreeing with you that some kind of mapper pattern is
desirable, but I'd want to separate the code which knows about the
persistent storage from the code which knows about the domain model.


I am in the middle of moving my Delphi OPF into C# 2.0. The code saving
using generics is absolutley mind-blowing. And finally I can use operator
overloading to give me a really simple syntax for concatenating Criteria for
submission to the OPF to retrieve lists, etc.


<- stuff ->

Very neat. I always think of the application to collections when
generics are mentioned, but that's a more better use for them. I've got
rid of a lot of the unpleasantness of SQL parameter building with a very
ugly base parameter wrapper class and a sly implicit cast to
SqlParameter:

public static implicit operator SqlParameter (ParameterBase p)
{
return p.underlyingPar ameter;
}

Unpalatable way of faking polymorphism because the nice people at
Microsoft made SqlParameter a sealed class, but it lets me pass my
subclasses to a command's parameters collection. I then have a plethora
of subclasses, many of which would be unnecessary with generics.
It just makes life so much easier not to have to think about DB related
stuff when you are designing systems.


Databases are a necessary evil as far as I'm concerned. The system I'm
gradually replacing is basically a monolithic architecture implemented
in TSQL with a thin ASP classic front end. Effectively uses some tables
as shared memory. Utterly terrifying to modify. It's fast, though, I'll
give it that.

--
Steve Walker
Nov 17 '05 #9
In message <#O************ **@tk2msftngp13 .phx.gbl>, "Joanna Carter
(TeamB)" <jo*****@nospam forme.com> writes
"Steve Walker" <st***@otolith. demon.co.uk> a écrit dans le message de news:
C7************ **@otolith.demo n.co.uk...
I can live with domain model
classes containing dependencies upon the names of columns in datatables,
but passing SqlTransaction objects around is just a bit too icky.
That's one way of describing it :-))


I was being polite :o)
So, I think I'm agreeing with you that some kind of mapper pattern is
desirable, but I'd want to separate the code which knows about the
persistent storage from the code which knows about the domain model.


I am in the middle of moving my Delphi OPF into C# 2.0. The code saving
using generics is absolutley mind-blowing. And finally I can use operator
overloading to give me a really simple syntax for concatenating Criteria for
submission to the OPF to retrieve lists, etc.


<- stuff ->

Very neat. I always think of the application to collections when
generics are mentioned, but that's a more better use for them. I've got
rid of a lot of the unpleasantness of SQL parameter building with a very
ugly base parameter wrapper class and a sly implicit cast to
SqlParameter:

public static implicit operator SqlParameter (ParameterBase p)
{
return p.underlyingPar ameter;
}

Unpalatable way of faking polymorphism because the nice people at
Microsoft made SqlParameter a sealed class, but it lets me pass my
subclasses to a command's parameters collection. I then have a plethora
of subclasses, many of which would be unnecessary with generics.
It just makes life so much easier not to have to think about DB related
stuff when you are designing systems.


Databases are a necessary evil as far as I'm concerned. The system I'm
gradually replacing is basically a monolithic architecture implemented
in TSQL with a thin ASP classic front end. Effectively uses some tables
as shared memory. Utterly terrifying to modify. It's fast, though, I'll
give it that.

--
Steve Walker
Nov 17 '05 #10

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

Similar topics

7
3119
by: David Mertz | last post by:
In the endless Lisp/macro threads, Alex Martelli mentioned something a bit interesting about screen-reading applications. Specifically, he expressed reservations about whether Python would be a good language for visually impaired or blind programmers. The concern, I think, is that pronouncing 'space-space-space-space-space-space-space-space' isn't all that easy to follow if spoken with every line. Even a reduced form like...
2
1376
by: Christopher T King | last post by:
Speakign of rounding errors, why is round() defined to round away from zero? I've always been quite fond of the mathematical definition of rounding of floor(n+.5). As a contrived example of why the latter is IMHO better, I present the following: for x in : print int(round(x)) This prints -10, -9, ..., -2, -1, 1, 2, ..., 9, 10 (it skips zero), probably not what you'd expect. I'm not sure how often a case like this
2
1406
by: Chinook | last post by:
I'm probably just getting languages mixed up, but I thought in my Python readings over the last couple months that I had noticed an either/or expression (as opposed to a bitwise or, or truth test). Being a curious sort, I tried several variations of how a list comprehension *might* be constructed and got the results expected relative to the operators, but not the results I was trying to achieve. So, is it possible to achieve what the...
4
1583
by: jbailo | last post by:
and it sounds GREAT !!! http://www.virginradio.co.uk/thestation/listen/ogg.html OGG OGG OGG ! ! !
7
1825
by: Neil Zanella | last post by:
OK, this time the compiler's got me a little bit puzzled, simply because it is doing something I am not expecting. My understanding, according to the documentation of std::vector<>::resize(), is that when you specify a second argument the number of elements specified in the first argument is each in turn set to the second argument. void Foo::bar(int x) { static std::vector<int> foo; std::cout << "source: " << x << std::endl;...
3
4162
by: Farouq | last post by:
dragon naturally speaking professional version 6.1 Hi all i have recently downloaded some examples from the dragon website in vb. I have managed to change some code to vba so that it could be used in MS access 2000. But i am stuck on this area, which is: ' Check for a valid speaker TryUsers
3
6223
by: jackiemasson | last post by:
Hi, I want to start Dragon Naturally Speaking when the user enters a field on an Access form and stop when they exit the field. I would like to save the audio file to a specific folder and pass the file name from a field value on the form. I also want the text to be inserted into the field. Does Dragon accept command line parameters on starting? Jackie Masson
4
1385
by: David C. Ullrich | last post by:
Mac OS X has text-to-speech built into the interface. So there must be a way to access that from the command line as well - in fact the first thing I tried worked: os.system('say hello') says 'hello'. Is there something similar in Windows and/or Linux? (If it's there in Linux presumably it only works if there
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.