Sean had a great post the other day in which he admitted (gasp) that
when he first starts an app he often just shoves logic directly into
controller methods in order to feed some wire-framed views. Then, as
the scope and function of the application come into focus he can break
things out -- personally, I've seen far too many folks try to start "The
Right Way" only to end up with an over-complicated mess of code that
isn't actually helping them get the job done (and often just has
components that do little more than duplicate methods in another
component, all in the name of implementing these patterns).
Separating concerns is a generally good thing to do, but only when it
actually saves you time/effort/maintenance -- and many apps are small
enough that they can start with just controllers and services (or
skipping services entirely and just having the controller call out to
implementations of your business logic in the model).
Having several distinct tiers and doing dependency injection and the
like can be very powerful, but if these concepts are new I think it
behooves you to discover their purpose "bottom-up" rather than
"top-down" -- break things out as it becomes clear when it would be a
lot easier if you did.
Personally, I think given that FW/1 already gives you a nice way to talk
to services a fine way to start is to turn off implicit services, then
put your business logic into the services folder and use the service()
method, or (as I showed in a previous post) create a very lightweight
implementation of the beanFactory interface that FW1 expects and put
your singleton services inside of it - then call those directly in your
controller. If later it turns your model is complex enough and clear
enough that it warrants being broken out separate from your services you
can refactor into a separate model layer and have your services use
those methods instead.
YMMV, of course.
- Nathan D
> --
> FW/1 on RIAForge: http://fw1.riaforge.org/
>
> FW/1 on github: http://github.com/seancorfield/fw1
>
> FW/1 on Google Groups: http://groups.google.com/group/framework-one
Which "relevant chapter" are you referring to?
> Understood that there are no single right answers but there must be a solid
> convention somewhere. Am I right that a model is just a simple bean with
> getters and setters but no smarts, i.e. business rules, and that the
> business rules tend to be embedded in the service object?
No, absolutely not. That would be a very procedural approach that left
you with dumb business objects - an anemic domain model.
In an MVC app, the Model is everything that isn't just "traffic cop"
logic (Controller) or View. Your application model includes a number
of (hopefully smart) business objects / domain objects as well as
services that orchestrate operations across multiple business objects
and perhaps provide a facade / API for the controller to use.
Make sense?
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
What's new to me is the notion of "service" as distinct from "model" so I was looking for use-cases that would help me understand the distinction and where I would put different types of code if I started making the distinction myself.
I'd strongly recommend not getting into this whole bean + DAO + gateway + service approach. You'll create a lot more objects than you need and you'll likely end up with an anemic domain model (a 'struct' for a bean and all your logic elsewhere).Here's what I recommend:- a bean per entity (nothing controversial there)- a gateway for each group of related entities - that handles both CRUD *and* aggregate queries- a service for each distinct area of your applicationThe services and gateways do not need to match up (they often will - they just don't have to)....The key is to keep as much business logic as appropriate in your domain objects so that services act only as coordinators for operations that must span multiple domain objects.
--
I've no idea what you mean. An application has a model. That model
includes services, business objects, the data access layer and so on.
> rule and I'm trying to follow a general guideline about what goes in a model
> vs. service, is it accurate to say that things are pushed down as specific
That question makes no sense. The service is part of your model
anyway. The business rules live _somewhere_ in your model.
> as they can go but no further? For example, a rule entirely specific to one
> bean gets implemented within that bean but a rule that requires knowledge
> across multiple beans goes in the service layer?
That's purely mechanics: a rule that applies across multiple business
objects generally has to live outside any specific business object -
it's orchestration, by definition. (technically you could designate
one business object as 'owning' the rule but the that object would
need to access / interact with the other object somehow)
Does that help?
If you are explicitly managing / calling services directly from your
controllers - i.e., not via the fw.service() method - then, yes, that
structure makes sense.
The top-level services/ folder is purely a convention / convenience
for FW/1 to auto-discover and instantiate service CFCs for you for
implicit calls to services.
FWIW, with DI/1, you'd be able to use your directory structure
(although the convention there is /model/beans for the transients :)
and just point DI/1 to the /model folder and have it auto-discover,
instantiate and inject your singleton and transient objects.
On Fri, Mar 4, 2011 at 7:46 AM, Dave Burns <goo...@burnsorama.com> wrote:What's new to me is the notion of "service" as distinct from "model" so I was looking for use-cases that would help me understand the distinction and where I would put different types of code if I started making the distinction myself.
I believe this is an incorrect notion. I generally think of the service layer as part of the model, because it's generally tightly coupled with business/domain objects in your model. Sean often refers to services as having the job of coordinating interactions between different business objects, and this of course creates fairly tight coupling between a service object and a group of closely related business objects.
On Wed, Jun 22, 2011 at 8:28 AM, Patti <greym...@gmail.com> wrote:
> I think a link to this topic would be at home on the "Helpful Links : Some
> Interesting discussions on Google Groups" page at GitHub
>
> --
> FW/1 on RIAForge: http://fw1.riaforge.org/
>
> FW/1 on github: http://github.com/seancorfield/fw1
>
> FW/1 on Google Groups: http://groups.google.com/group/framework-one
>
--
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)