Readers will learn to understand the proper uses of inheritance and composition, the difference between aggregation and association, and the important distinction between interfaces and implementations. While programming technologies have been changing and evolving over the years, object-oriented concepts remain a constant—no matter what the platform.
The object-oriented thought process
This revised edition focuses on interoperability across programming technologies, whether you are using objects in traditional application design, in XML-based data transactions, in web page development, in mobile apps, or in any modern programming environment. Stay ahead with the world's most comprehensive technology and business learning platform. With Safari, you learn the way you learn best. Patterns lend themselves perfectly to the concept of reusable software development. And because object-oriented development is all about reuse, patterns and object-oriented development go hand-in-hand.
The basic concept of design patterns revolves around the principle of best practices. By best practices, we mean that when good and efficient solutions are created, these solutions are documented in a way that others can benefit from previous successes—as well as learn from the failures. In writings on object-oriented topics, you will often see the Gang of Four referred to simply as the GoF.
Explaining each design pattern is far beyond the scope of this book and would take more than one volume. To accomplish this, we explore each of the three categories creational, structural, and behavioral of design patterns as defined by the Gang of Four and provide a concrete example of one pattern in each category. Why Design Patterns?
The concept of design patterns did not necessarily start with the need for reusable software.
The Object-Oriented Thought Process
In fact, the seminal work on design patterns is about constructing buildings and cities. Naming a pattern immediately increases our design vocabulary. It lets us design at a higher level of abstraction. Having a vocabulary for patterns lets us talk about them with our colleagues, in our documentation, and even to ourselves. It makes it easier to think about designs and to communicate them and their tradeoff to others. Finding good names has been one of the hardest parts of developing our catalog.
It explains the problem and its content. It might describe specific design problems, such as how to represent algorithms as objects. It might describe class or object structures that are symptomatic of an inflexible design. Sometimes the problem will include a list of conditions that must be met before it makes sense to apply the pattern. Instead, the pattern provides an abstract description of a design problem, and how a general arrangement of elements classes and objects in our case solves it.
Although consequences are often unvoiced, when we describe design decisions, they are critical for evaluating design alternatives and for understanding the costs and benefits of the applying pattern.
The Object-Oriented Thought Process (3rd ed.)
The consequences for software often concern space and time tradeoffs. They might address language and implementation issues as well.
Listing the consequences explicitly helps you understand and evaluate them. MVC is often used to illustrate the origins of design patterns. Smalltalk was perhaps the first popular objectoriented language. These ideas included the mouse and using a windowing environment, among others. Smalltalk is a wonderful language that provided the foundation for all the object-oriented languages that followed.
Design Patterns defines the MVC components in the following manner: The Model is the application object, the View is the screen presentation, and the Controller defines the way the user interface reacts to user input. The problem with previous paradigms is that the Model,View, and Controller used to be lumped together in a single entity. For example, a single object would have included all three of the components. With the MVC paradigm, these three components have separate and distinct interfaces.
So if you want to change the user interface of an application, you only have to change the View. Remember that much of what we have been learning about object-oriented development has to do with interfaces versus implementation. As much as possible, we want to separate the interface from the implementation. We also want to separate interface from interface as much as possible.
For example, we do not want to combine multiple interfaces that do not Chapter 15 Design Patterns have anything to do with one another or the solution to the problem at hand. The MVC was one of the early pioneers in this separation of interfaces. The MVC explicitly defines the interfaces between specific components pertaining to a very common and basic programming problem—the creation of user interfaces and their connection to the business logic and data behind them. If you follow the MVC concept and separate the user interface, business logic, and data, your system will be much more flexible and robust.
For example, assume that the user interface is on a client machine, the business logic is on an application server, and the data is located on a data server.
Developing your application in this way would allow you to change the way the GUI looks without having an impact on the business logic or the data. Likewise, if your business logic changes and you calculate a specific field differently, you can change the business logic without having to change the GUI.
- Point of Departure.
- Die Rolle des Partners in der Suchtberatung zwischen Co-Abhängigkeit und Unterstützung (German Edition);
- The Object-Oriented Thought Process (3rd ed.).
- All I Want For Christmas Is You!
- The Object-Oriented Thought Process, Fourth Edition.
- Ethan Justice: Relentless (Ethan Justice - A Private Investigator Series Book 2)!
- [PDF] The Object-Oriented Thought Process (Developer's Library) Pre O…?
And finally, if you want to swap databases and store your data differently, you can change the way the data is stored on the data server without affecting either the GUI or the business logic. This assumes, of course, that the interfaces between the three do not change. The listbox is the view, the phonelist is the model, and the controller is the logic thatbinds the listbox to the phone list.
MVC Drawbacks Although the MVC is a great design, it can be somewhat complex, in that there must be a lot of attention paid to the upfront design. This is a problem with object-oriented design in general—there is a fine line between a good design and a cumbersome design. The question remains: How much complexity should you build into the system with regard to a complete design? Types of Design Patterns Design Patterns features 23 patterns grouped into the three categories listed below. The publication date of was right at the cusp of the Internet revolution and the corresponding popularity of the Java programming language.
After the benefit of design patterns became apparent, many other books rushed in to fill the newly created market. Many of these later books were written in Java. In any event, the actual language used is irrelevant. Design Patterns is inherently a design book, and the patterns can be implemented in any number of languages. The authors of the book divided the patterns into three categories: n Creational patterns create objects for you, rather than having you instantiate objects directly. This gives your program more flexibility in deciding which objects need to be created for a given case.
Types of Design Patterns n n Structural patterns help you compose groups of objects into larger structures, such as complex user interfaces, or accounting data. Behavioral patterns help you define the communication between objects in your system and how the flow is controlled in a complex program. In the following sections, we will discuss one example from each of these categories to provide a flavor of what design patterns actually are.
For a comprehensive list and description of individual design patterns, please refer to the books listed at the end of this chapter. Creational Patterns The creational patterns consist of the following categories: n n n n n Abstract factory Builder Factory method Prototype Singleton As stated earlier, the scope of this chapter is to describe what a design pattern is—not to describe each and every pattern in the GoF book.
Thus, we will cover a single pattern in each category. For example, if you have a website that has a counter object to keep track of the hits on your site, you certainly do not want a new counter to be instantiated each time your web page is actually hit. You want a counter object instantiated when the first hit is made, but after that, you want to use the existing object to simply increment the count.
- Stay ahead with the world's most comprehensive technology and business learning platform..
- Sample Content.
- See a Problem?.
Client Figure Although there might be other ways to regulate the creation of objects, the best way is to let the class itself take care of this issue. Taking Care of Business Remember, one of the most important OO rules is that an object should take care of itself. This means that issues regarding the life cycle of a class should be handled in the class, not delegated to language constructs like static, and so on.
Note the property uniqueinstance, which is a static singleton object, and the method Instance. The other properties and methods are there to indicate that other properties and methods will be required to support the business logic of the class. Any other class that needs to access an instance of a Singleton must interface through the Instance method.
The creation of an object should be controlled through the constructor, just like any other OO design. We can require the client to interface through the Instance method, and then have the Instance method call the constructor. The following Java code illustrates what the code looks like for the general singleton. Only a single counter object can be created. In this event, a new Counter object is created. If the instance is not null, it indicates that a Counter object has been instantiated, and no new object is to be created.