• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

composition - cohesion relationship

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was hoping that someone here could help clarify something for me.

Composition represents a whole/part relationship where a part cannot exist without the whole.

Cohesion is used to group together related functionality.

So can it be said that composition must be used to create a cohesive design?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Schmoe wrote:I was hoping that someone here could help clarify something for me.

Composition represents a whole/part relationship where a part cannot exist without the whole.

Cohesion is used to group together related functionality.

So can it be said that composition must be used to create a cohesive design?



cohesion simply means that the class does ONLY that functionality which its supposed to do. e.g. a date class should only work with dates and nothing else, not even time. cohesiveness brings in single class single responsibility paradigm.

i do not see any mandate to use composition to achieve cohesiveness. why would you say so ?
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Joe Schmoe.

Private Message sent regarding a JavaRanch administrative matter.
 
Joe Bradley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to figure out how the concepts of association, aggregation and composition relate to SOA, loose coupling and cohesion.

Association is a relationship where one class uses another class.

Aggregation is a stronger form of association that represents a whole/part relationship where the part can exist without the whole (e.g. - Course/Student).

Composition is a stronger form of aggregation where the part cannot exist without the whole (e.g. - Room/House).

 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A service-oriented architecure adheres to a different architectural style than a component-based architecture. Traditional object-oriented design terms such as cohesion and coupling have different meanings when applied to SOA

In regards to UML relationships which describe "object" relationships, they don't have any meaning for anything other than "object" relationships and are not used in service-oriented analysis and design (SOAD).

Keep in mind that in a SOA you still have applications, and they may be object-oriented applications.
 
Joe Bradley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if a Course class has an instance variable for List<Student> then this would be association at a minimum because the Course class is using the Student class.

It seems like this could further be class aggregation since there is a whole/part relationship - an instance of the Student class would be part of the whole Course class but it seems like a Student class could live outside of the Course class. Read the rest of this post to understand my confusion regarding class aggregation vs object aggregation.

However, the rule of composition states that a class being used is limited to the lifetime of the container class. In this case if a Course object is disposed then its List<Student> is also disposed.

So it seems like a differentiation required between "class aggregation" and "object aggregation." It seems like this distinction may be required to correctly describe the relationship. How is this normally handled?
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stop thinking about classes for a while and think only in terms of "objects". In object-oriented programming, everything is an object, not a class. A class is simply a detailed description or a blueprint, that is all. In a JRE, at runtime, there are only objects. Note, when you start to code static classes and methods you start to move away from object-oriented programming and into structured programming.

It seems like this could further be class aggregation since there is a whole/part relationship - an instance of the Student class would be part of the whole Course class but it seems like a Student class could live outside of the Course class. Read the rest of this post to understand my confusion regarding class aggregation vs object aggregation.



If in "your" application, a Student object can exists without an owning Course object, then there isn't a Composition relationship between the two objects. This would be an example of an Aggregation relationship.

If in "your" application, a Student object cannot exist without an owning Course object, there there is a Composition relationship.

but it seems like a Student class could live outside of the Course class



If you write the code that makes this happen, then it happens. If you don't write the code then it doesn't happen. How do you determine what to do and how to design? You need to carefully read the business requirements of the application. Here in the requirements you will learn if a Student object can exist outside of a Course object.

If you don't have requirements, then you could run wild with you theories and hypothetical scenarios...
 
reply
    Bookmark Topic Watch Topic
  • New Topic