• 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

Role vs responsibility

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between role and responsibilty of a class? Examples will be helpful.
Thanks in advance.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A role defines one's relationship with others in the larger scheme of things. A responsibility is something that one must or is expected to do.
Real-world example:
Role: Parent
Responsibilities:
- Provide for basic needs of dependents
- Give guidance to dependents
- Be a role model
Role: Child
Responsibilities:
- Listen to and obey parent(s)
- Follow parent's example
- Help around the house

Software example:
Class: Animal
Role: Parent
Responsibility:
- Provide common attributes and methods
Class: Dog
Role: Child
Responsibility:
- Provide specific behavior for common methods defined by parent
- Provide specific values for attributes defined by parent
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With other words:
- a class should have exactly one responsibility, that is, it should provide one single form of service (e.g. a String provides common functionality on "lists of characters")
- a class can have many roles depending on the context it gets used in (e.g. the name of a customer) - in fact it would be more appropriate to speak of *instances* of classes to have roles...
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Thanx for the responses.
For the above posts I understand that "role" comes into picture only when we talk abt relations.
[ December 11, 2002: Message edited by: Pradeep Bhat ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
For the above posts I understand that "role" comes into picture only when we talk abt relations.


Yes, correct!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic