SENG 365 — Software Engineering
2026-10-01
By the end of this module, you should be able to:
Before class: You read Robillard, 3rd ed., Chapter 2, Sections 2.1–2.3.
You should arrive able to recognize:
public and private accessibility.Bring one question or point of confusion from the reading.
A program represents a playing card in one of these ways:
A Joker is added to the game. Which representation makes that change safest (and what do we mean by safe?)?
Write down:
Client code knows the encoding:
What can client code know, change, or accidentally corrupt?
The next release must:
Mark every line in the previous code artifact that might change.
What other client code would you search for?
With a partner, design one representation for Card.
Your design must address:
We will compare two proposals from the class.
| Question | Design A | Design B |
|---|---|---|
| What is stored? | ||
| What do clients see? | ||
| Can invalid cards exist? | ||
| How is a Joker represented? | ||
| Where does localization belong? | ||
| Which change is expensive? |
Complete both sentences:
Clients of
Cardshould know __________.Clients of
Cardshould not know __________.
Before class: Read all of Robillard, 3rd ed., Chapter 2. Focus on Sections 2.4–2.9.
You should arrive able to recognize:
Which return statement best preserves the encapsulation of a Deck?
Choose one, then identify the missing fact that could change your answer.
Assume Card is an immutable record.
The field is private. Is the representation hidden?
Without running the code:
exposed to the diagram.Deck.Using the object diagram, find two different routes by which a reference escapes.
For each route, state:
Deck invariant could be broken; andprivate did not prevent the problem.Revise the public interface of Deck. Your design must let a client:
cards() is called; andPossible ways to expose information include:
These are not interchangeable:
What behaviour does your client actually need?
And what behaviour should you anticipate, accommodate, or leave to future redesigns?
Write a small check that would distinguish the old and new designs:
Your check should expose an ownership or aliasing decision, not an implementation detail.
The requirements change: Card is now mutable.
Re-evaluate your design:
Deck?Card immutable, perform a deep copy, or expose a narrower query?What should happen when an empty deck receives draw()?
Client precondition
Validated operation
Who is responsible in each design? Which choice fits the expected clients of this class?
private field can still be exposed through aliases.Write one decision rule you would use next time:
Return a copy, view, or query when __________, because __________.

Course home · Neil Ernst ©️