Download presentation
Presentation is loading. Please wait.
Published byEileen Nash Modified over 9 years ago
1
The radio Has a case The case separates the controls on the outside (the client interface) from the electronic guts inside (the implementation).
2
The Radio Most electronic devices warn us not to break encapsulation with stickers that say things like, "This device should be serviced by certified professionals only. If you remove this panel, you will void your warranty."
3
Objects An object…. has state (its present condition - stores data). Has behavior (operations defined on it).
4
this radio object has fields that define its state Is it on or off? What station is it tuned to? What is the volume setting?
5
this radio object has Operations that involve : Observing the present state Look at settings (accesses information) Changing the present state Change settings (modifies state of radio)
6
myVolume myStation myIsOnStatus The Radio class setVolume() setIsOn() setStation() getVolume() getStation() getIsOn()
7
A class The description of what comprises an object of a particular type is a class class Radio would specify that an object (radio) has an on/off indicator, a station indicator, a volume indicator, and an on/off control, a station select control, a volume setting control. This is a definition of a radio.
8
this radio An object of this Radio class It has these controls We sometimes say: An instance of the Radio class We instantiate Radio….
9
Instances of the Radio class myVolume myStation myIsOnStatus setVolume() getVolume() other methods here
10
Given the Radio class We may define other derivative types: Cassette walkman IS-A radio Alarm clock radio IS-A radio Car radio IS-A radio
11
What about all of these radios?? ALL HAVE On-off control Volume control Station setting SOME HAVE MORE
12
Simple class Hierarchy diagram Radio isOnStatus myVolume myStation --------------------------- boolean getOnOffStatus() void setIsOnStatus() int getVolume() void setVolume() int getStation() void setStation() Walkman What does a walkman have that makes it more than a Radio? AlarmClockRadio alarmSetting alarmStatus -------------------------------------- someTimeType getAlamTime() void setAlarmTime() boolean getAlarmStatus() setAlarmStatus() CarRadio What does a car radio have that makes it more than a Radio?
13
And we can get as complicated as we want… What about our HomeEntertainment Center?
14
HomeEntertainmentCenter HAS-A Radio HAS-A Cassette Player HAS-A CDPlayer HAS-A DVDPlayer HAS-A Television
15
Maybe each of these 'pieces' is A subclass of an EntertainmentElectronicDevice class????
16
Using other objects… Some objects can be useful for building larger systems. A Radio may be a part of a home entertainment system that involves several other components. A Radio can be a subclass of some ElectronicEntertainment Device class. We still do not need to know the implementation details about the radio, only the interface for connecting it to other components.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.