Chapter Eight Expanding Our Horizons Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Advertisements

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Classes & Objects Computer Science I Last updated 9/30/10.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
CHAPTER 3 COLLECTIONS Abstract Data Types. 2 A data type consists of a set of values or elements, called its domain, and a set of operators acting on.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
© Wolfgang Pelz Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts.
Kari R. Schougaard, PhD Stud. Værktøjer og Teknikker, 2006 UNIVERSITY OF AARHUS Department of Computer Science Unified Modeling Language Visual language.
Chapter One The Object-Oriented Paradigm Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
1 Working with Classes Chapter 6. 2 Class definition A class is a collection of data and routines that share a well-defined responsibility or provide.
Chapter 22 Object-Oriented Design
BACS 287 Basics of Object-Oriented Programming 1.
Object Oriented Programming
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
Introduction to Object-oriented programming and software development Lecture 1.
CHAPTER ONE Problem Solving and the Object- Oriented Paradigm.
Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
Chapter Two The UML – Unified Modeling Language Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
Frameworks & Patterns Use of Organized Classes. Frameworks vs Toolkits Framework Framework  Start with classes and interfaces that define a rudimentary.
Chapter 18 The Observer Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Basic Concepts of Object Orientation Object-Oriented Analysis CIM2566 Bavy LI.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Chapter 21 Design Patterns Reviewed from the New Perspective of Object-Oriented Design Ku-Yaw Chang Assistant Professor, Department.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
Methodology First and Language Second -A Way to Teach Object-Oriented Programming Haibin Zhu, PhD Department of Computer Science and Mathematics Nipissing.
CS 4240: Rethinking Some OOP Ideas and Terms for OOA&D Readings: Chap. 8 in Shalloway and Trott (referred to as S&T in these slides) Wikipedia on information.
Scis.regis.edu ● CS-432: Modern Software Engineering Week 4 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Copyright 2006 Oxford Consulting, Ltd1 January Introduction to C++ Programming is taking A problem Find the area of a rectangle A set of data.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
ITEC0724 Modern Related Technology on Mobile Devices Lecture Notes #2 1.
Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Object-Oriented Programming: Inheritance and Polymorphism.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Object Oriented Paradigm OOP’s. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach.
CS 116 Object Oriented Programming II Lecture 9 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
11 Systems Analysis and Design in a Changing World, Fifth Edition.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Design Patterns: MORE Examples
Chapter Six The Facade Pattern
Chapter Nine The Strategy Pattern
The Object-Oriented Thought Process Chapter 1
OOP What is problem? Solution? OOP
Basic Object Oriented Approach
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Object Oriented Analysis and Design
Object Oriented Design & Analysis
The Object Paradigm Classes – Templates for creating objects
Presentation transcript:

Chapter Eight Expanding Our Horizons Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University

2Ku-Yaw ChangExpanding Our Horizons 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

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

4Ku-Yaw ChangExpanding Our Horizons 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

5Ku-Yaw ChangExpanding Our Horizons Objects The traditional view Data with methods Data with methods Smart data From implementation perspective The new view Things with responsibilities 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 Make a preliminary design without worrying about all of the details involved Implement the design Implement the design

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

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

8Ku-Yaw ChangExpanding Our Horizons 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

9Ku-Yaw ChangExpanding Our Horizons Encapsulation The traditional view Data hiding Data hiding Too limited Umbrella and car Umbrella and car The new view Any kind of hiding

10Ku-Yaw ChangExpanding Our Horizons Encapsulation Multiple levels of encapsulation Encapsulation of data Encapsulation of data Encapsulation of methods Encapsulation of methods Encapsulation of subclasses Encapsulation of subclasses Encapsulation of other objects Encapsulation of other objects

11Ku-Yaw ChangExpanding Our Horizons Inheritance In object-oriented paradigm Reuse of classes was one of its big benefits Reuse of classes was one of its big benefits Generalized class Specialized class Inheritance as a concept versus for reuse as a concept versus for reuse

12Ku-Yaw ChangExpanding Our Horizons Problems Can cause weak cohesion Different types of borders or other things Different types of borders or other things Pentagon aren’t just concerned about pentagons anymore Pentagon aren’t just concerned about pentagons anymore Reduces possibility of reuse Code for different borders Code for different borders Does not scale well with variation Need to specialize the pentagon class repeatedly Need to specialize the pentagon class repeatedly

13Ku-Yaw ChangExpanding Our Horizons 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

14Ku-Yaw ChangExpanding Our Horizons 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. 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.

15Ku-Yaw ChangExpanding Our Horizons 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 Change things on different sides of the layers without affecting the other side Loose-coupling between the sides Loose-coupling between the sides

16Ku-Yaw ChangExpanding Our Horizons Variation in Data Versus in Behavior Requirements Each type of animal can have a different number of legs Each type of animal can have a different number of legs Animal objects must be able to remember and retrieve this information Animal objects must be able to remember and retrieve this information Each type of animal can have a different type of movement Each type of animal can have a different type of movement Walking and flying Animal objects must be able to return how long it will take to move from one place to another Animal objects must be able to return how long it will take to move from one place to another Given a specified type of terrain

17Ku-Yaw ChangExpanding Our Horizons Variation in Data Versus in Behavior Solutions A data member A data member A choice of approach A choice of approach Having a data member Having two different types of Animals (both derived from the base Animal class) One for walking One for walking One for flying One for flying

18Ku-Yaw ChangExpanding Our Horizons Variation in Data Versus in Behavior Problems Too many details Too many details A plethora of classes Eagles : carnivores that fly Eagles : carnivores that fly Lions : carnivores that walk Lions : carnivores that walk Sparrows : vegetarians that fly Sparrows : vegetarians that fly Cows: vegetarians that walk Cows: vegetarians that walk Cannot handle Animals that can both walk and fly Weakly cohesive Weakly cohesive

19Ku-Yaw ChangExpanding Our Horizons Variation in Data Versus in Behavior Another possibility exists Have the Animal class contain an object that has the appropriate movement behavior Have the Animal class contain an object that has the appropriate movement behavior

20Ku-Yaw ChangExpanding Our Horizons Comparing the two Is one object containing another object inherently different from an object having a mere data member ? Are data members objects? 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 attributes Using objects to contain variation in behavior Using objects to contain variation in behavior

21Ku-Yaw ChangExpanding Our Horizons 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

22Ku-Yaw ChangExpanding Our Horizons Commonality and Variability Analysis Commonality analysis Identify where things vary Identify where things vary Search for common elements Variability analysis Identify how they vary Identify how they vary

23Ku-Yaw ChangExpanding Our Horizons Commonality/Variability and Abstract Classes

24Ku-Yaw ChangExpanding Our Horizons Two-Step Procedure When Defining You Must Ask yourself An abstract class (commonality) What interface is needed to handle all of the responsibilities of this class? Derived classes Given this particular implementation (this variation), how can I implement it with the given specification?

25Ku-Yaw ChangExpanding Our Horizons 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) 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)? Given this specification, how can I implement this particular case (this variation)?

26Ku-Yaw ChangExpanding Our Horizons 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

27Ku-Yaw ChangExpanding Our Horizons Summary Encapsulation Any kind of hiding Any kind of hiding More than simply hiding data Inheritance A method of consistently dealing with different concrete classes that are conceptually the same 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 Data members to hold variations in data Commonality/variability analysis More effectively than looking for nouns and actions More effectively than looking for nouns and actions

The End