















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















































































By
Gang Xu
Submitted in partial fulfillment of the requirements for the degree o f Master o f Computer Science
at
Dalhousie University Halifax, Nova Scotia March 2005
© Copyright by Gang Xu, 2005
Library and Archives Canada Published Heritage Branch 395 W ellington StreetOttawa ON K1A 0N Canada
Bibliotheque et Archives Canada Direction du Patrimoine de I'edition 395, rue W ellingtonOttawa ON K1A 0N Canada Your file Votre reference ISBN: 0-494-00927- Our file Notre reference ISBN: 0-494-00927-
The author has granted a non exclusive license allowing Library and Archives Canada to reproduce, publish, archive, preserve, conserve, communicate to the public by telecommunication or on the Internet, loan, distribute and sell theses worldwide, for commercial or non commercial purposes, in microform, paper, electronic and/or any other formats.
L'auteur a accorde une licence non exclusive permettant a la Bibliotheque et Archives Canada de reproduire, publier, archiver, sauvegarder, conserver, transmettre au public par telecommunication ou par I'lnternet, preter, distribuer et vendre des theses partout dans le monde, a des fins commerciales ou autres, sur support microforme, papier, electronique et/ou autres formats.
The author retains copyright ownership and moral rights in this thesis. Neither the thesis nor substantial extracts from it may be printed or otherwise reproduced without the author's permission.
L'auteur conserve la propriete du droit d'auteur et des droits moraux qui protege cette these. Ni la these ni des extraits substantiels de celle-ci ne doivent etre imprimes ou autrement reproduits sans son autorisation.
In compliance with the Canadian Privacy Act some supporting forms may have been removed from this thesis. While these forms may be included in the document page count, their removal does not represent any loss of content from the thesis.
Conformement a la loi canadienne sur la protection de la vie privee, quelques formulaires secondaires ont ete enleves de cette these. Bien que ces formulaires aient inclus dans la pagination, il n'y aura aucun contenu manquant.
i * i
Acknowledgements
This thesis was written under the supervision of Dr. Morven Gentleman, to whom I am grateful for his guidance and help. Throughout the process of my thesis writing, I received many valuable suggestions from him. His advice about thesis organization and writing helped me to manage my research and thesis writing. His ideas about frameworks and genetic algorithms also greatly inspired me. I would also like to thank Dr. Anthony Cox and Dr. Peter Hitchcock, who took their valuable time to review my work, provide detailed comments and challenge my ideas. Finally, I am grateful to my wife and parents, for their everlasting love and support.
xi
1
The idea of software reuse has been present being since the very beginning of software development history. In its early years, software reuse was mainly concemed with the reuse of code and supported by subroutine libraries. Since the 1980s, object-oriented techniques have been becoming more and more popular because of their powerful support for software reuse in a number of ways. Software reusability is greatly improved by object-oriented features such as data abstraction, encapsulation, inheritance, polymorphism and late binding. Based on object-oriented techniques, design patterns and object-oriented frameworks are two important software reuse technologies.
Design patterns support the reuse of software design. They describe proven successful solutions to commonly recurring design problems in a particular context. They came into being as documentation of expertise from expert software designers. Among hundreds of design patterns [1], the design patterns [2] introduced by Gamma et al. (also called the “Gang of Four” or GoF) are the most widely studied and used by software developers to improve the quality o f their design. The primary benefit that design patterns bring to a software product is flexibility and maintainability.
Object-oriented frameworks [3] (here after “frameworks” for simplicity) are a higher level of software reuse technique that have been becoming increasingly popular in contemporary s oftware development. T hey a re h ighly u seful f or r educing t he c ost a nd improving the quality o f software by reusing proven successful design as well as implementation. Framework development differs from traditional object-oriented software development. Traditional object-oriented development focuses on a single problem in an application domain and usually doesn’t put much emphasis on software extensibility. However, extensibility and flexibility are the key issues in framework development. Framework developers have to thoroughly analyze the whole application
3
This thesis is organized as follows: Chapter 2 introduces and studies design patterns, their underlying principles, how they solve problems, and the benefits that they provide. GoF design patterns are primarily discussed in this chapter. Chapter 3 studies the development of object-oriented frameworks. Frameworks and their characteristics, how frameworks are compared with design patterns and other reuse techniques, white-box and black-box frameworks, essential construction patterns of frameworks, how to find GoF patterns for framework design, and hot-spot-driven development process are discussed in this chapter. Chapter 4 describes the development of a framework for genetic algorithms as a case study. I first make a brief introduction to genetic algorithms and then illustrate the whole development process and design considerations. An example of how to specialize the framework demonstrates how application development effort is reduced by the reuse of domain analysis, design and code. Finally, Chapter 5 presents the conclusion, what I have learned from this study, and suggestions for future research directions.
4
Christopher Alexander, an architect, first studied patterns in buildings and communities and developed the idea of pattern language to enable people to design their own buildings and communities [4]. Alexander used a pattern to describe a reoccurring problem in construction environment, and the core of the solution to the problem. In such a way, people can reuse the solution over and over without having to work it out for themselves. This kind of mechanism for design reuse can also be applied to the development of object-oriented software. For the reuse of object-oriented designs, we describe design solutions in terms of classes, interfaces and object collaborations instead o f walls, doors and windows. The core of both kinds of design patterns has been proven to be successful solutions to specific problems in a context [2].
Design patterns describe common structures of communicating components for solving general design problems in particular contexts [2]. They generally consist of four essential elements: 1) A pattern name that highly abstracts a design with regards to the problem, the solution and consequences. It enables easier thinking about designs and communications with others. 2) A problem that describes the context for when and where to use the pattern. It may express specific design problems, an inflexible design, or a set of conditions to apply the pattern. 3) A solution that describes classes and objects that compose the design, including their relationships, responsibilities and collaborations. It is generally applicable for many different situations rather than specific for a particular concrete design. 4) A set of consequences that indicate the advantages, drawbacks, and trade-offs of applying a pattern. They a re very valuable for evaluating design solution alternatives and being aware of benefits and costs of a pattern.
A design pattern is neither about a concrete design implementation which can be reused as is nor about a complex domain-specific design for an application or subsystem. Instead,
6
generality for application framework development, I put my research effort to the study of GoF patterns.
Because there are a total of 23 GoF design patterns, classifying them into different families gives us a way to organize them, understand them better and find them faster. Gamma et al. classify their design patterns according to two criteria, purpose and scope (see Table 1 which is adopted from [2]). The purpose criterion classifies GoF patterns according to what they do. The three classifications are creational, structural, and behavioral patterns. Creational patterns deal with the process o f object creation. Structural patterns concern the composition of classes and object. Behavioral patterns emphasize how classes or objects communicate and how to distribute responsibilities. The scope criterion classifies GoF patterns according to their primary applicability to classes or objects. Class patterns are about the relationships of classes and their subclasses. Such relationships are implemented through class inheritance. They are static and cannot be changed at run-time. Object patterns emphasize object relationships, which are changeable at run-time and more dynamic.
Purpose Creational Structural Behavioral
Class Factory Method^ Adapter^ InterpreterTemplate Method
Scope Object
Abstract Factory Builder Prototype Singleton
Adapter Bridge Composite Decorator Facade Proxy
Chain of Responsibility Command Iterator Mediator Memento Flyweight Observer State Strategy Visitor Table 1 Classification of GoF patterns by purpose and scope
7
The construction of design patterns is based on several fundamental principles such as abstraction, information hiding, indirection, low coupling and high cohesion. Making these principles clear helps us to understand design patterns and how expert designers think, and how to produce a good software design. The following is a discussion about these underlying principles.
Abstraction. Abstraction is a fundamental principle people use to deal with complexity. According to Grady Booch [9], abstraction is the essential characteristics o f an object which make it different from other kinds o f objects, and provides a crisp conceptual boundary in terms of the viewers’ perspective. Abstraction exists in several forms such as entity abstraction, behavior abstraction and coincidental abstraction [10]. Many design patterns, such as the Abstract Factory and the Composite, utilize this principle.
Information hiding. Information hiding is often archived by encapsulation, which is one of the fundamental features of object-oriented programming [11]. By hiding implementation details from clients, we can better handle software complexity and reduce coupling between components. For example, the Proxy and Bridge patterns hide object presentation and implementation information from clients to avoid cascading effect o f changes. Information hiding fosters the non-functional properties of software, such as changeability and reusability.
Polymorphism. Polymorphism is a fundamental principle in software design to allow similar behavior variations [12], Enabled by the abstraction of similar or related services, polymorphism allows different objects to share a common interface but have different implements. With polymorphism, extensions for new behaviors can be easily added and new implementation can be introduced without affecting clients. Many design patterns such as the Adapter, Strategy and Proxy rely on a polymorphism mechanism.
9
benefits us in understanding the role design patterns play in software development. Gamma et al. [2] described the following design problems and how they are solved by design patterns.
1) Bridging the gap between the analysis model and the design model. Objects are the building blocks of object-oriented programs. The decomposition of a system into objects is a hard part of object-oriented design. Object-oriented analysis methodologies, such as use cases, CRC (for Class, Responsibility, and Collaboration) cards [13] and domain modeling, help designers find objects in the real world. However, during the transformation o f an analysis model into a design model, w e s truggle t o find o bjects t hat h ave n o corresponding o nes i n t he r eal world. Design patterns help bridge this gap between the analysis model and the design model.
Determining the size and number of objects. An object-oriented program usually consists of different numbers of objects o f different sizes. Design patterns take this issue into account and provide design solutions for objects at different level of granularity. For example, the Facade pattern considers a complete subsystem as an object while the Flyweight pattern supports high volume of objects at the smallest granularity.
Defining the interfaces of objects. As a fundamental mechanism o f object- oriented programming, interfaces are the only way to access objects. The separation of the definition of an interface from its different implementations allows the substituting o f objects that have identical interfaces at run-time. This is known as polymorphism, one of the features of object technology. Design patterns i dentify t he k ey e lements and t he t ypes o f d ata t ransferred t hrough an interface, and thus, help to determine what to put in the definition o f the interface. Design patterns also describe requirements of the relationship between interfaces.
Defining the implementation of objects. Objects are implemented by defining classes. Classes define objects’ internal data and the implementation of their
10 operations, while class inheritance provides a mechanism to reuse the functionality of existing classes. However, implementation dependency comes with class inheritance. Clients are aware of the classes that implement the objects they are using. This kind of dependency can be reduced by interface inheritance if care is used when inheriting from an abstract class which specifies a shared interface. Design patterns follow this principle and offer different ways to associate an interface with its implementation transparently at instantiation.
a. Preference for object composition rather than class inheritance. Object composition and class inheritance, respectively referred to as black-box and white-box reuse, are both common object-oriented reuse techniques. Class inheritance is defined by sub-classing statically at compile-time. Users are required to be aware o f the internals of parent class. It is easy to modify the implementation being reused. However, the reused implementation cannot be changed at run-time (except by using a pure abstract parent class) and there lies the implementation dependency of subclasses upon the parent class. Object composition is dynamically defined by keeping references to existing objects at run-time. Composed objects have carefully defined interfaces and users have no knowledge of the internals of objects being composed. Object composition offers benefits including reduced implementation dependencies, better class encapsulation, less classes and less complex class hierarchies. In practice, class inheritance is used to assist object composition by making it convenient to create new kinds of objects which can be composed with old ones.