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

Advice on good OO design

Hi,

I'm just getting started with real OO design and programming and am
after a little advice.

Basically, I've got a Customer class and an Agency class. The Agency
class inherits all the properties and methods from Customer but I have
come accross a couple of problems:

I've got a Save, Add and Delete method in both of the objects. I'm going
on the assumption that it's a good idea to allow each object to control
itself. Each of these methods in the Agency class override the methods
in the Customer class and the base.Save etc methods are added to each of
the methods in the Agency class to fire off the assiciated method in the
Customer class before performing it's own Save etc.

I would like to pass in a database connection object to these classes
and force the Save methods to run in a transaction as there's no point
saving the Agency details without the Customer details. This is the area
that is causing me problems. I am currently passing the connection and
transaction objects directly into the Agency object via a constructor
and I then set relevant properties in the Customer object using
base.localDbConnection so that the Customer object has a connection to
work with. Bearing in mind that I am probably going to introduce
additional variants of Customer later, is this a good way of managing
the database connections etc ?

Any advice would be appreciated.

Rob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
3 2399
I don't think you should allow your customer class (put aside any
inheritence issues a sec) to add, save or delete themselves at all.
Think about it from a Real World perspective. You don't call up John
the customer and ask him to drop by and delete himself from your
records. You have an administrator... or a "factory class"... handle
the responsibilities of creating, modifying and removing customers
(and other objects) from the data storage container.

Rob Thomas <ro*@rtcomputersystems.com> wrote in message news:<uw**************@TK2MSFTNGP11.phx.gbl>...
Hi,

I'm just getting started with real OO design and programming and am
after a little advice.

Basically, I've got a Customer class and an Agency class. The Agency
class inherits all the properties and methods from Customer but I have
come accross a couple of problems:

I've got a Save, Add and Delete method in both of the objects. I'm going
on the assumption that it's a good idea to allow each object to control
itself. Each of these methods in the Agency class override the methods
in the Customer class and the base.Save etc methods are added to each of
the methods in the Agency class to fire off the assiciated method in the
Customer class before performing it's own Save etc.

I would like to pass in a database connection object to these classes
and force the Save methods to run in a transaction as there's no point
saving the Agency details without the Customer details. This is the area
that is causing me problems. I am currently passing the connection and
transaction objects directly into the Agency object via a constructor
and I then set relevant properties in the Customer object using
base.localDbConnection so that the Customer object has a connection to
work with. Bearing in mind that I am probably going to introduce
additional variants of Customer later, is this a good way of managing
the database connections etc ?

Any advice would be appreciated.

Rob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2
This is known as Responsibility Driven OOP. The question to ask is
"who's responsibility is it to perform this action". Your example of
the Customer coming over to delete himself from the database
is a perfect example of placing the responsibility on the wrong class.
Great example !

This is the biggest mistake new OO programmers make. They use
objects to do procedural programming. I have found that by asking
the simple question or responsibility, that these problems can be
turned from procedural to OO
JIM
"Chris Hornberger" <ch***@chornbe.com> wrote in message
news:53**************************@posting.google.c om...
I don't think you should allow your customer class (put aside any
inheritence issues a sec) to add, save or delete themselves at all.
Think about it from a Real World perspective. You don't call up John
the customer and ask him to drop by and delete himself from your
records. You have an administrator... or a "factory class"... handle
the responsibilities of creating, modifying and removing customers
(and other objects) from the data storage container.

Rob Thomas <ro*@rtcomputersystems.com> wrote in message

news:<uw**************@TK2MSFTNGP11.phx.gbl>...
Hi,

I'm just getting started with real OO design and programming and am
after a little advice.

Basically, I've got a Customer class and an Agency class. The Agency
class inherits all the properties and methods from Customer but I have
come accross a couple of problems:

I've got a Save, Add and Delete method in both of the objects. I'm going
on the assumption that it's a good idea to allow each object to control
itself. Each of these methods in the Agency class override the methods
in the Customer class and the base.Save etc methods are added to each of
the methods in the Agency class to fire off the assiciated method in the
Customer class before performing it's own Save etc.

I would like to pass in a database connection object to these classes
and force the Save methods to run in a transaction as there's no point
saving the Agency details without the Customer details. This is the area
that is causing me problems. I am currently passing the connection and
transaction objects directly into the Agency object via a constructor
and I then set relevant properties in the Customer object using
base.localDbConnection so that the Customer object has a connection to
work with. Bearing in mind that I am probably going to introduce
additional variants of Customer later, is this a good way of managing
the database connections etc ?

Any advice would be appreciated.

Rob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #3
eing one of the few people that ever write a professional commercial
persistence layer (for .NET, btw.) let me second this.

Load, Save, query etc has NOTHING to do with the object per se - these are
operations that belong to a manager class. Not to the object.

BESIDES you never save the object, you save the object plus maybe subobjects
that got created etc.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)

"Chris Hornberger" <ch***@chornbe.com> wrote in message
news:53**************************@posting.google.c om...
I don't think you should allow your customer class (put aside any
inheritence issues a sec) to add, save or delete themselves at all.
Think about it from a Real World perspective. You don't call up John
the customer and ask him to drop by and delete himself from your
records. You have an administrator... or a "factory class"... handle
the responsibilities of creating, modifying and removing customers
(and other objects) from the data storage container.

Rob Thomas <ro*@rtcomputersystems.com> wrote in message

news:<uw**************@TK2MSFTNGP11.phx.gbl>...
Hi,

I'm just getting started with real OO design and programming and am
after a little advice.

Basically, I've got a Customer class and an Agency class. The Agency
class inherits all the properties and methods from Customer but I have
come accross a couple of problems:

I've got a Save, Add and Delete method in both of the objects. I'm going
on the assumption that it's a good idea to allow each object to control
itself. Each of these methods in the Agency class override the methods
in the Customer class and the base.Save etc methods are added to each of
the methods in the Agency class to fire off the assiciated method in the
Customer class before performing it's own Save etc.

I would like to pass in a database connection object to these classes
and force the Save methods to run in a transaction as there's no point
saving the Agency details without the Customer details. This is the area
that is causing me problems. I am currently passing the connection and
transaction objects directly into the Agency object via a constructor
and I then set relevant properties in the Customer object using
base.localDbConnection so that the Customer object has a connection to
work with. Bearing in mind that I am probably going to introduce
additional variants of Customer later, is this a good way of managing
the database connections etc ?

Any advice would be appreciated.

Rob


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #4

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

Similar topics

5
by: Martin Piper | last post by:
Hi all. I've recently landed myself the position of trainee C++ programmer which I'm extremely pleased about, but also nervous. According to the feedback from the interview, I have a good...
2
by: Andrew | last post by:
I am starting my first C# project and have a design issue which I would appreciate some advice about. I am wondering whether to use dataset to pass information between components or if I should...
5
by: Nick Malik | last post by:
reposting to a wider audience "Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message news:WYONc.203854$XM6.119642@attbi_s53... > My turn to ask a question > > I am working on a plug-in...
4
by: Nick Malik | last post by:
My turn to ask a question I am working on a plug-in for Sharepoint that will allow a developer to add workflow rules. One of the rules will inform the adapter that it should load a DLL that the...
3
by: Robert W. | last post by:
Following the advice of several of you on here (Thank You All!) I've successfully constructed a Model-View-Controller (MVC) implementation. It works great! Now, whenever the user manipulates one...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
11
by: dydx31 | last post by:
Hey guys, I am a Computer Science student attending classes at the University of Michigan-Dearborn. I have been in college for a few years now, but I have some questions for you. I am really...
22
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.