Hands-On Design Patterns with Java
上QQ阅读APP看书,第一时间看更新

Creating concise objects

Objects are at the core of OOP. This principle aims to remind software designers and developers to isolate objects to a specific model. Using our Bicycle class as an example, we would create Bicycle objects that contained the appropriate attributes and behaviors. The bicycle attributes used in this chapter were gears, cost, weight, and color. We created accessors and mutators for each of those attributes. We also created a method that echoed the object's attributes to the output console. No behaviors were added to the Bicycle object, but we could have included behaviors such as upgrade()

What we did not include in the Bicycle class were attributes and behaviors that were ancillary to the Bicycle object. Examples of these include the owner's address, vacation details, and more. While the data might be somewhat related to a specific Bicycle, it is not part of a real-world bicycle that we need to model.

Adhering to this principle helps ensure our code is concise, easy to maintain, and portable.