1 / 25

Chapter Eight Expanding Our Horizons

Chapter Eight Expanding Our Horizons. Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University. Outline. Overview Objects: the Traditional View and the New View

Télécharger la présentation

Chapter Eight Expanding Our Horizons

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter EightExpanding Our Horizons Ku-Yaw Chang canseco@mail.dyu.edu.tw Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University

  2. Outline • Overview • Objects: the Traditional View and the New View • Encapsulation: the Traditional View and the New View • Find What is Varying and Encapsulate It • Commonality/Variability and Abstract Classes • Summary Expanding Our Horizons

  3. Overview • Fundamental concepts • Objects • Encapsulation • Abstract • A new way of seeing object-oriented design • From the perspective that design patterns create Expanding Our Horizons

  4. Outline • Overview • Objects: the Traditional View and the New View • Encapsulation: the Traditional View and the New View • Find What is Varying and Encapsulate It • Commonality/Variability and Abstract Classes • Summary Expanding Our Horizons

  5. Objects • The traditional view • Data with methods • Smart data • From implementation perspective • The new view • Things with responsibilities • From conceptual perspective • Focus on what the objects are supposed to do • Make a preliminary design without worrying about all of the details involved • Implement the design achieved. Expanding Our Horizons

  6. Objects • Things with responsibilities • Easier to think in terms of responsibilities • Help to define the object’s public interface • For example • A Shape object’s responsibilities • To know where it is located • getLocation( … ) • drawShape( … ) • unDrawShape( … ) • To be able to draw itself on a display • To be able to remove itself from a display Expanding Our Horizons

  7. Objects • Focus on motivation rather than on implementation is a recurring theme in design patterns. • Basic viewpoint for objects • Superior designs Expanding Our Horizons

  8. Outline • Overview • Objects: the Traditional View and the New View • Encapsulation: the Traditional View and the New View • Find What is Varying and Encapsulate It • Commonality/Variability and Abstract Classes • Summary Expanding Our Horizons

  9. The traditional view Data hiding Too limited Umbrella and car The new view Any kind of hiding Encapsulation Expanding Our Horizons

  10. Encapsulation • Multiple levels of encapsulation • Encapsulation of data • Encapsulation of methods • Encapsulation of subclasses • Encapsulation of other objects Expanding Our Horizons

  11. Inheritance • In object-oriented paradigm • Reuse of classes was one of its big benefits • Generalized class • Specialized class • As a concept versus for reuse Expanding Our Horizons

  12. Outline • Overview • Objects: the Traditional View and the New View • Encapsulation: the Traditional View and the New View • Find What is Varying and Encapsulate It • Commonality/Variability and Abstract Classes • Summary Expanding Our Horizons

  13. Find What Is Varying and Encapsulate It • GoF suggests the following • Consider what should be variable in your design. This approach is the opposite of focusing on the cause of redesign. Instead of considering what might force a change to a design, consider what you want to be able to change without redesign. The focus here is on encapsulating the concept that varies, a theme of many design patterns. Expanding Our Horizons

  14. Find What Is Varying and Encapsulate It • Use encapsulation to create layers between objects • Change things on different sides of the layers without affecting the other side • Loose-coupling between the sides Expanding Our Horizons

  15. Variation in Data Versusin Behavior • Requirements • Each type of animal have a different number of legs • Each type of animal have a different type of movement • Walking and flying • Solutions • A data member • A choice of approach • Having a data member • Having two different types of Animals Expanding Our Horizons

  16. Variation in Data Versusin Behavior • Problems • Tightly coupling • Too many details • Manage the subtype of Animal • Cannot handle Animals that can both walk and fly • A third possibility exists • Have the Animal class contain an object that has the appropriate movement behavior Expanding Our Horizons

  17. Variation in Data Versusin Behavior Expanding Our Horizons

  18. Comparing the two • Is one object containing another object inherently different from an object having a mere data member ? • Are data members objects? • In object-oriented programming, everything is an object. • Using objects to contain variation in attributes • Using objects to contain variation in behavior Expanding Our Horizons

  19. Outline • Overview • Objects: the Traditional View and the New View • Encapsulation: the Traditional View and the New View • Find What is Varying and Encapsulate It • Commonality/Variability and Abstract Classes • Summary Expanding Our Horizons

  20. Commonality/Variability and Abstract Classes Expanding Our Horizons

  21. Two-Step Procedure Expanding Our Horizons

  22. Relationships • The relationship between the specification perspective and the conceptual perspective • It identifies the interface I need to use to handle all of the cases of the concept (that is, the commonality) • The relationship between the specification perspective and the implementation perspective • Given this specification, how can I implement this particular case (this variation)? Expanding Our Horizons

  23. Outline • Overview • Objects: the Traditional View and the New View • Encapsulation: the Traditional View and the New View • Find What is Varying and Encapsulate It • Commonality/Variability and Abstract Classes • Summary Expanding Our Horizons

  24. Summary • Encapsulation • Any kind of hiding • More than simply hiding data • Inheritance • A method of consistently dealing with different concrete classes that are conceptually the same • Not a means of specialization • Using objects to hold variations in behavior • Data members to hold variations in data Expanding Our Horizons

  25. The End

More Related