UML Weekend Crash Course⢠- To Parent Directory
UML Weekend Crash Course⢠- To Parent Directory UML Weekend Crash Course⢠- To Parent Directory
Session 3—How to Approach the UML 31 been driving for two years and still doesn’t know about them. The information that the car exposes so that someone can use the car is called the car’s interface. The interface is how you communicate to the car that you want to use one or more of the car’s behaviors. For example, when you press on the gas pedal, you’re telling the car to go faster. So in order to use an object, you need to expose the interface of the object, like the car interface in Figure 3-6. Figure 3-6 The interface for a car allows us to use the car. To make the object work properly I remember as a kid our neighbors had the old shell of a car in a field behind the house. It had brake and gas pedals, a steering wheel, a gearshift, and so on. But wish as we might, the car never responded. An interface without an implementation doesn’t do much. We could communicate with the object, but the object didn’t have any way to respond. In order to make the object work, you need to provide the mechanisms that respond to the interface. Here is where it all starts to come together. Remember back to the part about what an object knows When you press the gas pedal, the behavior (the implementation behind that interface) needs to know how the car is put together and the state of the car. An object knows about itself, so the car would know how it is put together and its current state. More than that, the knowledge must not be altered inappropriately or the behavior won’t work properly. Consequently, encapsulation tells you that the information has to be inside the object with the behavior so that you can control access to it and protect its integrity. This is why encapsulation is often called information hiding. You hide the information inside the object, where the object has complete control. For example, Figure 3-7 illustrates the hidden, internal mechanisms that make an engine work properly. In order to make the object work properly, you need to place inside the object: The implementations for each interface The data that describes the structure of the object The data that describes the current state of the object
32 Friday Evening Exhaust manifold Fuel injection system Oil filter Pulley Figure 3-7 Mounts Waterpump Alternator Belt Crankshaft pulley Defining the internal design of an object so that it will work properly Giving an object purpose If you leave encapsulation with this description, you have a bit of a problem. Many objects can have the same interface. Just think for a minute about all the objects you know of that share the interfaces accelerate, decelerate, turn, start, and stop, such as those shown in Figure 3-8. Figure 3-8 Purpose drives the design and use of an object. The go-cart and luxury car in Figure 3-8 share all these interfaces. But you would never use them both in the same way. If interface alone doesn’t adequately distinguish objects, then what else do you need in order to define an object Purpose. You need to know why that type of object exists, what it was designed for. The interface is designed to satisfy the purpose. Encapsulation summary Encapsulation of an object requires you to expose: Its purpose, so you can select the proper object for the application you have in mind Its interface, so you know how to use the object
- Page 4 and 5: UML Weekend Crash Course Thomas A.
- Page 6 and 7: About the Author Tom Pender is the
- Page 8: With thanks to Lynne Angeloro for h
- Page 11 and 12: x Preface To get the most out of th
- Page 13 and 14: xii Preface Features First, as you
- Page 15 and 16: Part VI—Sunday Afternoon ........
- Page 17 and 18: xvi Contents Encapsulation ........
- Page 19 and 20: xviii Contents Modeling the Class C
- Page 21 and 22: xx Contents Session 22-Modeling the
- Page 24: UML Weekend Crash Course
- Page 27 and 28: PART I Friday Evening Session 1 Wha
- Page 29 and 30: 6 Friday Evening The UML is a stand
- Page 31 and 32: 8 Friday Evening will find three pa
- Page 33 and 34: 10 Friday Evening The Continuing Re
- Page 36 and 37: SESSION 2 UML and Development Metho
- Page 38 and 39: Session 2—UML and Development Met
- Page 40 and 41: Session 2—UML and Development Met
- Page 42 and 43: Session 2—UML and Development Met
- Page 44 and 45: Session 2—UML and Development Met
- Page 46 and 47: SESSION 3 How to Approach the UML S
- Page 48 and 49: Session 3—How to Approach the UML
- Page 50 and 51: Session 3—How to Approach the UML
- Page 52 and 53: Session 3—How to Approach the UML
- Page 56: Session 3—How to Approach the UML
- Page 59 and 60: 36 Friday Evening Remember to pay c
- Page 61 and 62: 38 Friday Evening Constraints The s
- Page 63 and 64: 40 Friday Evening An Inventory Cont
- Page 65 and 66: 42 Friday Evening Performance How
- Page 67 and 68: 44 Friday Evening In the effort to
- Page 70 and 71: Part II — Saturday Morning Sessio
- Page 72 and 73: SESSION 5 Understanding the Use Cas
- Page 74 and 75: Session 5—Understanding the Use C
- Page 76 and 77: Session 5—Understanding the Use C
- Page 78 and 79: Session 5—Understanding the Use C
- Page 80 and 81: Session 5—Understanding the Use C
- Page 82: Session 5—Understanding the Use C
- Page 85 and 86: 62 Saturday Morning Order Fulfillme
- Page 87 and 88: 64 Saturday Morning What does the
- Page 89 and 90: 66 Saturday Morning For example, th
- Page 91 and 92: 68 Saturday Morning REVIEW The goal
- Page 93 and 94: 70 Saturday Morning Much of this la
- Page 95 and 96: 72 Saturday Morning You reply that
- Page 97 and 98: 74 Saturday Morning Writing a Use C
- Page 99 and 100: 76 Saturday Morning Use Case dialog
- Page 101 and 102: 78 Saturday Morning Table 7-7 The F
32<br />
Friday Evening<br />
Exhaust<br />
manifold<br />
Fuel injection<br />
system<br />
Oil filter<br />
Pulley<br />
Figure 3-7<br />
Mounts<br />
Waterpump<br />
Alternator<br />
Belt<br />
Crankshaft pulley<br />
Defining the internal design of an object so that it will work properly<br />
Giving an object purpose<br />
If you leave encapsulation with this description, you have a bit of a problem. Many objects can<br />
have the same interface. Just think for a minute about all the objects you know of that share<br />
the interfaces accelerate, decelerate, turn, start, and stop, such as those shown in Figure 3-8.<br />
Figure 3-8 Purpose drives the design and use of an object.<br />
The go-cart and luxury car in Figure 3-8 share all these interfaces. But you would never use<br />
them both in the same way. If interface alone doesn’t adequately distinguish objects, then<br />
what else do you need in order to define an object Purpose. You need to know why that type<br />
of object exists, what it was designed for. The interface is designed to satisfy the purpose.<br />
Encapsulation summary<br />
Encapsulation of an object requires you to expose:<br />
Its purpose, so you can select the proper object for the application you have in mind<br />
Its interface, so you know how to use the object