Re: Class design question
- From: "Daniel T." <postmaster@xxxxxxxxxxx>
- Date: Wed, 26 Apr 2006 19:32:36 GMT
In article <1146045782.921174.194370@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"sundeep" <sundeeps@xxxxxxxxx> wrote:
Hi,
Let me first describe the requirement. I have to design a small system
that should be able to manage websites on a hosting environments. The
tasks that i need to do are
- CreateWebSIte
- DeleteWebSite
- ModifyWebSite
- ChangeIPAdress
Now, I have two options to design the Biz functionlity.
You have a lot more than the two options you specified...
What i want to know is the difference in two options i mentioned,
merits and demerits, recomended approach as per OO design principles.
An ideal OO program works like a termite colony where each object is
like a termite. No object is ever told what to do, they just react to
their environment. That's not to say that it's wrong to demand objects
enter certain states, just know that it's not "OO" to do so (IE your
working in the procedural realm at that point.)
Now there are two ways of setting up such a system. One is to simply
notify objects when a change in their environment occurs and let them
inspect the environment and decide what to do about it. This method is
characterized by very few "mutator" methods and lots of "getter"
methods. For example, when a new IP address has been entered by the
user, the WebSite object is given a "environChanged" message, the
WebSite object at this point should already have a reference to its
environment, so it would ask the appropriate environment what the new IP
address is and change itself.
The second method is to inform objects directly what has changed, this
is characterized by lots of mutator methods and few getter methods. An
example here would be sending a "newIPAddressAvailable" message with the
new IP address attached. The WebSite object can then choose to accept
the new address or not at its will.
In either case, the mutator methods are requests or notifications, *not*
demands. Your not telling the WebSite object to change its IP address,
you are simply letting it know it can if it wants to.
As far as your specified options. The second one looks like a Command
pattern. I wouldn't use it unless I needed to be able to back out a
series of requests, or needed to queue up requests to be executed later,
or send requests over a network, or log a series of requests that would
need to be resent later. In C++ such a system is also used to create
callbacks (called "functors" among C++ people.) Other languages usually
have some sort of method/block/lambda object and therefore don't need
functors.
The reason I wouldn't use it unless I had to, is because it's much more
complex than simply sending requests to objects.
.
- References:
- Class design question
- From: sundeep
- Class design question
- Prev by Date: Re: Class design question
- Next by Date: Re: Question on LSP
- Previous by thread: Re: Class design question
- Next by thread: how to represent multiobject in Rational Software Architect
- Index(es):
Relevant Pages
|