(That said, you're providing very minimal information and all design
patterns have trade offs so choosing them needs to be based on pros
_and_ cons)
I would decouple the behavior from the inheritance much as I suggested
with Strategy and Factory. It's a common mistake in OO to overuse
inheritance.
I'll be interested to hear what others have to say about this :)
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
Not really. You're starting from a position where you already have an
object structure in place and assuming it's right ("Shouldn't they
belong to VoteService.cfc?").
Please at least go read the Strategy and Factory Method patterns so
you can see what I'm suggesting...
On Wed, Jul 13, 2011 at 6:25 PM, Sean Corfield <seanco...@gmail.com> wrote:
>
> Please at least go read the Strategy and Factory Method patterns so
> you can see what I'm suggesting...\
--
You received this message because you are subscribed to the Google Groups "Object-Oriented Programming in ColdFusion" group.
To post to this group, send email to coldfu...@googlegroups.com.
To unsubscribe from this group, send email to coldfusionoo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldfusionoo?hl=en.
The best reference is the "Gang of Four" book: Design Patterns by
Gamma, Helm, Johnson, Vlissides. I've heard the Head First Design
Patterns book is quite good too.
I think you're trying to run before you can walk. Design Patterns
really only make sense when you have a fair bit of OO experience and
you've run into the problems that they can help you solve - and you
have enough experience to recognize those problems.
I think you just need to focus on implementing solutions to your
problems without worrying about design patterns or the "best" way to
do things.
OO is hard. You can't "get it" from books alone and you can't "do it
right" first time - it simply isn't possible (unless you are some sort
of savant that was born with a universal understanding of modeling the
world in software terms).
> This lead me to believe that only the objects themselves should have methods
> to modify them. This is why the most natural solution seemed a
> VoteService.cfc that just handles all the business logic.
But that's the _opposite_ of a an object with methods that mutate.
Services don't have state so any methods are by definition going to
operate on _other_ objects.
The vote knows who is voting, and what / who is being voted on. The
strategy would know _what_ to do and the vote would pass the
appropriate actors to the strategy.
I think you're implementing the behaviors (strategies) as methods in
the service - or as conditional behavior within the service? That's
what I'm suggesting you abstract out - and remove the service
altogether. The strategy then becomes an attribute of the specific
vote instances, supplied by the factory method that knows how to
create specific vote instances.
My advice to you is probably going to sound a bit confusing:
Keep doing exactly what you're doing. Don't worry about patterns,
don't worry about best practices. Just do your own thing.
When you start to find pain points in what you're doing, read the
design patterns book. Keep reading it until you start to connect the
Context of the patterns to your problem and recognize the Pressures in
those patterns.
In other words, until you are experiencing pain - and can connect that
to specifics in the patterns - you don't need patterns.
I think you're looking at patterns as code? That's not the right
approach. Patterns aren't code, they're concepts and templates for
design. Hopefully my other answer will help more...
What might help is to take the Gang of Four patterns book and read
each pattern - without looking at the Implementation or Sample Code
sections at all, just focusing on the pattern motivation,
applicability and consequences (that's one of the most important part:
the trade offs you make by using a pattern).
Only once you truly understand the pattern itself, can you see whether
it might help or hinder your particular problem / solution. Don't
expect that understanding to come quickly, tho'...
It's important to remember that these patterns were grown organically
out of lots of software experience and each pattern can have multiple
implementations that may also look very different in each language. I
used to give a talk on Design Patterns in CFML where I showed how
certain core patterns are trivial in CFML but extremely hard in Java
(Singleton, for example). I urged folks not to follow the pattern
implementations because they'd look different in CFML and if you're
not careful, you'll end up with Java-in-CFML or C++-in-CFML which is
not a good idea. At the time, I suggested folks look to Ruby for
inspiration rather than Java (although Ruby's metaprogramming
capabilities far outstrip CFML). In general, Java is a very poor model
for expanding your OO skills, esp. when you work with CFML for a
living. Ruby and Python are better models (dynamic scripting
languages) but those communities don't tend to worry much about design
patterns (possibly because they're not needed as much or they're
already baked into some of their common idioms?). Robert C. Martin
calls Ruby and Python "Smalltalk in C clothing" which is a pretty good
way to think of it (in the context of the GoF book having examples in
Smalltalk).
The Clojure community, for example, doesn't pay much attention to
design patterns. The question came up on the main mailing list one day
and it was pointed out that several common design patterns are either
inherent to the way people normally write Clojure code or the
implementation is so trivial as to be almost non-existent. In other
words, many of the patterns have already been internalized and so
folks don't need to agonize over whether to "apply" a design pattern
to their code.