SENG 365 — Software Engineering
2026-10-21
By the end of this module, you should be able to:
Before class: Read Chapter 6, Sections 6.1–6.3.
A theatre program can contain a movie, a double bill, or a festival of programs.
int duration(Object show) {
if (show instanceof Movie movie) return movie.duration();
if (show instanceof DoubleBill bill)
return duration(bill.first()) + duration(bill.second());
if (show instanceof Festival festival)
return festival.shows().stream()
.mapToInt(this::duration).sum();
throw new IllegalArgumentException();
}What new structure causes another branch?
Design a component type and object graph (see 6.2) for:
Movie as a leaf;Program as a group;Produce a class diagram and one example object graph. State what client code becomes simpler.
Can your design represent:
Uniform treatment simplifies clients but can make invalid object graphs easier to construct. Who enforces the invariant?
The Null Object example is useful when an absent child must safely receive the same operation:
Compare it with an empty collection, Optional<Show>, and null. Use it only when “do nothing” has valid domain meaning.
Composite simplified __________, but __________ must still enforce __________.
Before class: Read Chapter 6, Sections 6.4–6.8.
A coffee shop offers milk, syrup, extra shots, and whipped cream in any combination.
Compare one subclass per combination with one class containing option flags. Which change hurts each design?
A decorator implements Beverage, wraps another Beverage, delegates, and adds one responsibility.
Sketch:
cost().Then compare the design with a simple list of additions. What justifies the pattern’s extra indirection?
The wrappers retain the component type while adding behavior. Chaining is powerful, but the original object’s identity is no longer the client’s main abstraction.
A menu item currently performs work directly:
What if the application must queue, log, replay, or undo operations?
Design a command for an editor action. Show:
execute() and, if justified, undo();Compare the object design with storing a lambda. When does a named command earn its cost?
Polymorphic copying can create a fresh object when the concrete type is unknown at compile time. Prototype names this situation.
Prefer a copy constructor when the type is known. Java cloning is complex and should not be the default.
Decorator or Command is heavier than the problem deserves when __________.
Before class: Review Sections 6.3 and 6.9.
Reference types: Foundations, Pile, List<Card>, and Card.
What knowledge does this client need? Which object should own “add this card to the first foundation”?
Draw a sequence diagram for the message chain.
Include:
Then mark the dependency that makes a change to Pile or its collection ripple into the client.
Sketch a second interaction:
Where did the knowledge go? Did coupling disappear, or move behind a more stable interface?
A method should normally collaborate with:
“One dot” is only a warning heuristic. Fluent APIs, value navigation, and collection pipelines may be acceptable. Ask whether the chain exposes unstable structure.
The chain __________ is acceptable/problematic because __________.

Course home · Neil Ernst ©️