1

I wonder if I have multiple objects and how to list their responsibilities where

every Object Must be Responsible for Itself

for example: If I have three objects:

Employee,Schedule,Shift.

and the setShift(), createShedule(),....etc


Where should these behaviors belong to ? in the Employee or in the objects which affected by these actions!!

It's very confusing because I ended up that most of the methods belong to one object in my case Employee! It turns to like a god/master object.

  • Possible duplicate of Explanation on how "Tell, Don't Ask" is considered good OO – gnat Apr 5 '18 at 9:50
  • 1
    You need to better explain what you mean by "responsible for itself". Right now, it is not clear what you are asking. – Euphoric Apr 5 '18 at 9:50
  • with regards to avoiding god object, see also How to determine if a class meets the single responsibility principle? – gnat Apr 5 '18 at 9:51
  • @Euphoric I mean where should I put the responsibilities in the employee who does the action or for example shift which affected by the action – Anyname Donotcare Apr 5 '18 at 9:52
  • It seems all you have done so far is define the domain objects. You still need something that typically sits outside that to tell the objects what to do - possibly using some kind of design pattern. Hard to advise further without a bit more detail. – Robbie Dee Apr 5 '18 at 10:16
3

I think you missed a domain object. The scheduler.

dayShift.setShift("7am","3pm");
shifts.add(dayShift);
Schedule schedule = evenHoursScheduler.createSchedule(shifts, employees);

Not every domain object is an object you can point to in the real world. Sometimes it's a role to be played.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.