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.

Slides:



Advertisements
Similar presentations
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
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.
ITEC200 – Week03 Inheritance and Class Hierarchies.
UML – Class Diagrams.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Slide 1 Systems Analysis & Design CS183 Spring Semester 2008 Dr. Jonathan Y. Clark Course Website:
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
Object Oriented Concepts. Movement toward Objects Instead of data-oriented or process-oriented Analysis, many firms are now moving to object-oriented.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
1 INTRODUCTION TO OOP Objective: Know the difference between functional programming and OOP Know basic terminology in OOP Know the importance of OOP Know.
Domain Modeling (with Objects). Motivation Programming classes teach – What an object is – How to create objects What is missing – Finding/determining.
Introduction To System Analysis and design
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
Object Oriented Analysis By: Don Villanueva CS 524 Software Engineering I Fall I 2007 – Sheldon X. Liang, Ph. D.
Design Patterns.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CS 4240: Bridge and Abstract Factory Readings:  Chap. 10 and 11 Readings:  Chap. 10 and 11.
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
BTS430 Systems Analysis and Design using UML Domain Model Part 1—Finding Conceptual Classes.
Chapter 1 Object-Oriented Analysis and Design. Disclaimer Slides come from a variety of sources: –Craig Larman-developed slides; author of this classic.
Unified Modeling Language, Version 2.0
Introduction To System Analysis and Design
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Slide 1 Structural Modeling Chapter 7. Slide 2 Key Ideas A structural or conceptual model describes the structure of the data that supports the business.
CSSE 374: More GRASP’ing for Object Responsibilities
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
DAAD project “Joint Course on OOP using Java” On Object Oriented modeling in Java (Why & How) Ana Madevska Bogdanova Institute of informatics Faculty of.
1 What is OO Design? OO Design is a process of invention, where developers create the abstractions necessary to meet the system’s requirements OO Design.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Object Oriented Software Development
CS2110: SW Development Methods Inheritance in OO and in Java Part 2: Topics: Forms of inheritance Interfaces in Java.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Salman Marvasti Sharif University of Technology Winter 2015.
CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could.
12 OBJECT-ORIENTED DESIGN CHAPTER
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
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.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Chapter Eight Expanding Our Horizons Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Object Oriented Programming and Data Abstraction Earl Huff Rowan University.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
Basic Characteristics of Object-Oriented Systems
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Cmpe 589 Spring 2006.
Chapter 1: Introduction to Systems Analysis and Design
Object-Oriented Analysis and Design
Chapter 11 Object-Oriented Design
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Basic OOP Concepts and Terms
Chapter 22 Object-Oriented Systems Analysis and Design and UML
Object Oriented Design & Analysis
Chapter 1: Introduction to Systems Analysis and Design
HFOOAD Chapter 5 Interlude
Presentation transcript:

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 hiding This unit is about principles and concepts – study the readings!

In Chap. 8, authors argue: Designers need to think about OO in a "new", "fresh", "non-traditional" way  in particular, about three terms: objects, encapsulation, inheritance Is this really new? Maybe better to say:  more mature, experienced perspective  more abstract Later we’ll use language features to support higher- level design needs But in design, focus on higher-level issues

What are objects? We learn early that they’re:  Data with methods  Visibility: public, private, etc  Supports information hiding, encapsulation Good match for:  domain concepts  data objects

S&T's “New” View of Objects An object is: An entity that has responsibilities  may include providing and managing information Focus here on what it does, not how An external view We can design using objects defined this way (without other details)

Adopt this view? Let's think this way for OO analysis and design.  What's the role of the object? From the point of view of the rest of the system  What does it provide us? What does it do for us? Makes sense for the conceptual and specification levels of design. More general: non-domain, non-data objects

S&T's New View of Encapsulation Old/Beginner/Implementation view of encapsulation: hiding data inside an object New view: hiding anything, including:  implementation  derived classes  design details  instantiation rules

Encapsulation means hiding Examples. (See book too.) Hiding data  Encapsulating data in objects; getters; etc. Hiding method implementation details  Polymorphism with pointers to superclasses, interfaces; abstract methods Hiding other objects  Composition; delegation; Façade pattern Hiding type  pointers to superclasses or interfaces; factories for creating objects

Really a New View of Encapsulation? Information hiding: (from Wikipedia) Information hiding is the principle of segregation of the design decisions in a computer program that are most likely to change, thus protecting other parts of the program from extensive modification if the design decision is changed. The protection involves providing a stable interface which protects the remainder of the program from the implementation (the details that are most likely to change). Read:

Information Hiding and David Parnas Term introduced in a famous paper: David Parnas, "On the Criteria to Be Used in Decomposing Systems Into Modules.” Comm. of the ACM, Parnas is an important figure in SW Engin. Keep in mind about Information [sic] Hiding:  “Information” does not mean just data encapsulation  Not just limited to OO

S&T's View of Inheritance Don't focus so much on inheritance for reuse Recall "specialization form" of inheritance?  Override methods to created different, specialized behavior  Extension form: add new behaviors (also applies here) S&T say, for design, think about inheritance as a way to identify things with common behaviors  Not about implementation. We’re doing design.  Inheritance/generalization in design may not lead to inheritance in implementation!

Book's example: page 122 Class Pentagon has drawBorder() Subclass PentagonSpecialBorder() overrides method Seems fine! The IS-A relationship is true, and can and should be used in design! Problems if you implement it that way:  Weak cohesion: the subclass contains pentagon-stuff and border-stuff  Poor reuse: other shapes need special-border code?  Doesn't scale: other dimensions of variability (we've seen this – inheritance “diamonds”)

Important Encapsulation Principle Find What Varies and Encapsulate It Gang of Four wrote about this (p. 123): Consider what should be variable in your design. Don't focus on what might force a design change. Instead, what do you want to be able to change without large-scale design change? Encapsulate that thing that you want to vary.

Example: Hiding "Type” A reference (or pointer) X can be assigned the address of an object that is:  the declared class of the reference  a class that is a subclass of class of reference  a class that implements interface of reference Client-code using X doesn't have to know which What’s “behind X” could change without affecting design of client-code Type encapsulation: The “real” type is “hidden”

Comments You've seen many examples of this! Study two examples in S&T, pp Animal generalization, with variations in:  how it moves (walk, fly, swim)  what it eats (meat, veggies,...)  Understand what’s said about UML diagrams Money, Currency classes  Conversion is supported, even historical  Note this is hidden from client SalesReceipt

Animal Example Encapsulate movement behavior  Note superclass is abstract (could be an interface)

Commonality and Variability Analysis (CVA) “CVA” as described by James Coplien Commonality analysis  Goal: determine family members and how they are the same  Family members: elements that appear in the same situation or perform the same function  Note: this is a process of identifying and analyzing generalizations

Variability Analysis Different elements are not exactly the same Are the differences enough to mean they're not family members? If not, then you're showing how family members vary. This is variability analysis.  Can't talk about variability within a family unless you have defined the family (i.e. done commonality analysis).  "CA" and "VA" are probably not linear, sequential processes. Iterative activity!

Coplien says: CA seeks structure that is unlikely to change over time. VA captures structure that is likely to change. VA only makes sense in terms of the context defined by CA. CA gives an architecture longevity. VA drives architecture’s “fitness for use”. (I.e. can it successfully solve specific problems?) (Paraphrased from quote on p. 128 in S&T book)

An Aside about Software Reuse There are fields in SW Engin.: Software reuse, domain engineering, product-line development CVA is important in domain analysis  Identifying common objects in a product domain or product line What's the same? How do things vary?  Goal: build an architecture or components that can be re-used to develop many products in the domain or product line.

S&T on Identifying Classes The naive approach: find nouns, verbs, etc.  S&T say: often leads to too many classes Contrast with CRC: classes, responsibilities, collaborations S&T talk about:  Objects are entities with responsibilities  Inheritance? Focus on finding commonalities in things to identify general abstractions  Then make these abtractions/interfaces/layers in your design.

Back to 3 Levels of Design Perspective For documenting and doing design, different levels of perspective: Conceptual; Specification; Implementation Commonality Analysis and Conceptual level  What are the entities and their commonalities?  What are the abstractions? These will become superclasses, interfaces, etc. At the Specification Level:  Need APIs to support what's common  And, must be able to hide variability behind these APIs

Summary OO Design: different kind of thinking about objects, encapsulation, generalization than what you learn as an OO Programmer Encapsulation: Hiding something from client  Same idea as information hiding  A rule: Find What Varies and Encapsulate It Commonality and Variability Analysis  An activity in OOA and OOD that can help produce stronger designs