2

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.

Anyname Donotcare
  • 1,364
  • 2
  • 16
  • 29
  • Possible duplicate of [Explanation on how "Tell, Don't Ask" is considered good OO](https://softwareengineering.stackexchange.com/questions/157526/explanation-on-how-tell-dont-ask-is-considered-good-oo) – gnat Apr 05 '18 at 09: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 05 '18 at 09:50
  • with regards to avoiding god object, see also [How to determine if a class meets the single responsibility principle?](https://softwareengineering.stackexchange.com/q/154723/31260) – gnat Apr 05 '18 at 09: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 05 '18 at 09: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 05 '18 at 10:16

1 Answers1

4

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.

Robbie Dee
  • 9,717
  • 2
  • 23
  • 53
candied_orange
  • 102,279
  • 24
  • 197
  • 315