• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Coarse grained v/s fine-grained objects

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are Coarse grained and fine-grained objects. Which one is recommended?

Thanks.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see this kind of granularity discussion usually in services and APIs. Coarse grained means a single call will do more work, fine grained means it might take several calls to get the same work done. Coarse grained is often better in distributed systems because calls between distributed components can be expensive and time consuming. Fine grained might be better in a very flexible system because clients could invent new combinations of calls to do new tasks.

Does that sound like it fits the question?
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stan for your input.

May be I am wrong but what I was thinking, coarse object means a *big* object, that has much responsibility. For example, suppose we are designing a system and we have identified logical entities (business domain objects) (I am not sure, it is right term or not) and now we want to come up with java classes corresponding to those. So should we try to map one entity to one java class (coarse object) or try that one entity should include many classes (each one will be fine object)...

Hope my point is clear.

Please comments.
Thanks.



 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a lot of reasons to favor relatively small objects with crystal clear behavior and responsibility. The theory stretches back to the 70s with information hiding, low coupling and high cohesion. The practice pays off every day.

Larger objects that gather up more responsibility, behavior and data become harder and harder to develop, test, modify, reuse, read, deploy, etc.

There are some patterns like Facade that put large grained interfaces in front of small grained objects to protect clients of a service from having to understand all the tricky bits within.

Fine grained objects often appear in rich domain models with lots of interesting behavior and well hidden data. In architectures like stateless web servers you can wind up with an Anemic Domain Model that looks good this way at first glance, but turns out to do nothing but push data around.

Any of that help?
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Stan. Thanks. May be I will ask some more questions on this after reading some information.
[ November 18, 2005: Message edited by: rathi ji ]
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic