












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The process of applying object-oriented design (ood) principles to system development. It covers the identification of classes and messages based on problem statement nouns and verbs, and provides examples of resulting classes and their interactions. The document also discusses the liskov substitution principle and the difference between composition and inheritance.
Typology: Study notes
1 / 20
This page cannot be seen from the preview
Don't miss anything!













Applying Object-Oriented Design
Thermostat Dial setting Heater Temperature Room
Finding Classes
Does noun represent class needed in design? Noun may be outside system Noun may describe state in class
Finding Classes
Possible to make everything its own class Approach taken in Smalltalk Overly complex 2+3 = 5 vs. NUM 2 .add(NUM 3 ) = NUM 5 Impact of design More classes more abstraction, flexibility Fewer classes less complexity, overhead Choice (somewhat) depends on personal preference
Singleton classes
For example, you might have a class Person, and a singleton subclass Elvis
Examples – class ListSorter, NameFinder Unless you might have multiple verb classes that all implement a common interface The Strategy design pattern
Finding Messages
Does verb represent interaction between objects?
Assign methods to classes to perform interaction
Analyzing Verbs
“Thermostat uses dial setting…” Thermostat.setDesiredTemp(int degrees)
“To control a heater…” Heater.turnOn() Heater.turnOff()
“To maintain constant temperature in room” Room.getTemperature()
Resulting Classes
State – dialSetting Methods – setDesiredTemp()
State – heaterOn Methods – turnOn(), turnOff()
State – temp Methods – getTemperature()
Subtypes
then Y is a subtype of both X and A
Anyone who expects a P can be given a Q
Not always strictly followed, but an ideal to approach For example, some iterators don’t support remove
Which could be a subtype?
is-a vs. has-a
A Car object has a reference to an Engine object has-a The Car class is a subtype of Engine is-a
Forms of Inheritance
Adds new functionality to subclass In Java → new method
Restricts behavior of subclass In Java → override method, throw exception
Inherits features from multiple superclasses Also called multiple inheritance Not possible in Java In Java → implement interface instead
Multiple Inheritance Example
AlarmClockRadio has two parent classes State & behavior from both Radio & AlarmClock Superclasses