Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've posted questions pertaining to this issue before, but they've all tackled different aspects of the problem (Just so you know that I'm not reposting the same question to get more answers).

So, in a nutshell, here is my problem: I have a Timeline class, which has-a Content interface member variable. The Timeline manages WHEN the content gets activated. There is also a Trigger class, which gets a reference to the Timeline class and call the Timeline's play() methods at certain times (like when the user hits spacebar). To organize the Triggers and the Timeline together, they're bound together in a class called Cue (which is the only class the rest of the program cares about).

This leads me to a design problem, since this Cue class is used so often throughout my code, it would be a pain to change it later.

Because of the Law of Demeter, should I not make getters and setters for the timeline and triggers member variables, and instead copy many of their functions into Cue (and just call the functions of the member variables in turn). That way, other classes won't know the inner workings of it?

share|improve this question
add comment

1 Answer

Because of the LoD, should I not make getters and setters for the timeline and triggers member variables, and instead copy many of their functions into Cue (and just call the functions of the member variables in turn). That way, other classes won't know the inner workings of it?

I would resolve this in one of three ways, depending on the Timeline / Trigger operations that must be performed in the application code.

If the application code needs to be able to call most methods of Timeline and Trigger, then adding delegations to Cue is pointless. Every addition to Timeline or Trigger will require a corresponding change in Cue, and you will have made the code worse, not better.

If the application code needs to call many methods, but some methods must not be called on objects encapsulated in a Cue, then I might create new interfaces for Timeline and Trigger that expose only those methods, and have Cue publish those interfaces instead of the full interfaces.

If the application code needs perform only a few operations on Timeline and Trigger, or only a few special sequences of operations, then I would add methods do Cue and hide the contained Timeline and Trigger.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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