CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
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.
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
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.
Object-Oriented PHP (1)
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,
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts.
The Software Design Process CPSC 315 – Programming Studio Fall 2009.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
Chapter 22 Object-Oriented Design
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
BACS 287 Basics of Object-Oriented Programming 1.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
A quadratic equation is a second degree polynomial, usually written in general form: The a, b, and c terms are called the coefficients of the equation,
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
Using Classes Object-Oriented Programming Using C++ Second Edition 5.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
1 Design and Integration: Part 1 Nuggets about Design vs Project Management.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Introduction to Object-oriented programming and software development Lecture 1.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Access Control.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
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.
Object Oriented Programming with JAVA Arash N. Kia AlZahra University Definitions – Part 1.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
CS 350 – Software Design The Strategy Pattern – Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore.
CS 350 – Software Design The Observer Pattern – Chapter 18 Let’s expand the case study to include new features: Sending a welcome letter to new customers.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
240 3/30/98 CSE 143 Object-Oriented Design [Chapter 10]
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
1 Design and Integration: Part 2. 2 Plus Delta Feedback Reading and lecture repeat Ambiguous questions on quizzes Attendance quizzes Boring white lecture.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
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.
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.
Session 3 How to Approach the UML Written by Thomas A. Pender Published by Wiley Publishing, Inc. October 5, 2011 Presented by Kang-Pyo Lee.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
Chapter Eight Expanding Our Horizons Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
CS 350 – Software Design The Adapter Pattern – Chapter 7 Gang of Four Definition: Convert the interface of a class into another interface that the client.
Object- oriented Design Principles
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
Object Oriented Paradigm OOP’s. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach.
CS 350 – Software Design The Facade Pattern – Chapter 6 Many design patterns are catalogued in the “Gang of Four” text. I find their definitions not to.
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Object Oriented Systems Design
Copyright © Jim Fawcett Spring 2017
Object-Orientated Programming
Section 2.1: Programming paradigms
JAVA By Waqas.
CS 350 – Software Design The Strategy Pattern – Chapter 9
Section 2.1: Programming paradigms
Object Oriented Practices
CS 350 – Software Design A Standard Object-Oriented Solution – Chapter 4 Before studying design patterns, many programmers solve a problem by starting.
CS 350 – Software Design Principles and Strategies – Chapter 14
Object-Oriented PHP (1)
Object Oriented Design & Analysis
HFOOAD Chapter 5 Interlude
Presentation transcript:

CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could be referred to as “Smart Data.” Indeed, when I learned objects, this is how I thought of them. However, it is better to think of them as “entities that have responsibilities.” This helps us focus on what objects are supposed to do. By focusing on what an object is supposed to do, you can hide the implementation details. This causes us to focus on an object’s public interface. If you focus on the public interface, then you do not need to know what is going on inside the object. This enables you to delegate responsibility.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Think about the Shape example. What responsibilities does a Shape have? To know where it is located. To know where it is located. To be able to draw itself on a display. To be able to draw itself on a display. To be able to remove itself from a display. To be able to remove itself from a display. This implies three methods: getLocation(…) getLocation(…) drawShape(…) drawShape(…) unDrawShape(…) unDrawShape(…) We do not need to know anything about the inner workings of the Shape class. Shape could contain attributes or another object. We do not care.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Hiding the implementation of Shape behind interfaces essentially decouples them from the using objects. Decoupling is the key to good design. It means that if something changes on the other side of the interface, the non-changed side should not require alteration.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Most of us learned encapsulation as data hiding. Before we improve that definition (ok, we already did earlier), here’s a nice little story. Many have accused me of being a tech gadget nut. So let me tell you about my cool umbrella. It is large enough to get into! In fact I have fit three or four people in it. While we are in there, staying out of the rain, I can even move from one place to the other. Of course, it has a stereo system to keep me entertained while I stay dry. It even has an air conditioner and heater. This is one cool umbrella. It was not cheap. An additional feature is my umbrella will even wait for me. It also has wheels so I do not have to carry it around. It even has a motor to self propel it.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Actually many people have umbrellas like this. It’s called a car. Of course a car isn’t an umbrella, but it does serve the purpose of one. The view that an car is an umbrella, may not be wrong, but it is a very limited view of a car. Long story to say, encapsulation isn’t just data hiding. Encapsulation is any kind of hiding. You can hide: Implementations Implementations Derived Classes Derived Classes Design Details Design Details Instantiation Rules Instantiation Rules

CS 350 – Software Design Expanding Our Horizons – Chapter 8 The Adapter pattern example shows many kinds of encapsulation. Can you name them?

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Encapsulating data Encapsulating data Encapsulating methods Encapsulating methods Encapsulating other objects Encapsulating other objects Encapsulating shapes Encapsulating shapes

CS 350 – Software Design Expanding Our Horizons – Chapter 8 In this case encapsulation is achieved with the use of an abstract class and derivations. We make use of polymorphism. By encapsulating shapes, I can add new ones without changing the client program. Early promoters of OOP touted reuse of classes as being one of its big benefits. This reuse was usually achieved by creating classes and then deriving new classes based on these base classes. The sub classes were called specialized classes. This is a fair way of developing, but leads to issues.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Imagine you have a class called Pentagon to contain state, draw, undraw, and so on. Later you decide you also want a special Pentagon with a special border. The traditional approach would be to create a Pentagon with a special border class that is derived from Pentagon.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 This approach has a lot of problems. Some will become more obvious as we progress. Weak Cohesion: What happens if we have lots of borders? If each border is a separate class then related code is being divided up. Reduces reuse: What happens if I want to reuse the special border for other shapes? This solution does not allow that to occur. Doesn’t scale well: What happens if other things vary? Combinatoric explosion!

CS 350 – Software Design Expanding Our Horizons – Chapter 8 A better solution is to use inheritance to classify classes as things that behave the same way. Consider what should be variable in your design (not always easy) and encapsulate it. Many design patterns use encapsulation to create layers between objects. This enables the designed to change things on different sides of the layer without adversely affecting the other side. This promotes loose coupling between the sides.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Consider the traditional problem of creating classes that represent animals. Your requirements are: 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 Animal objects must be able to move from place to place given a specified type of terrain Animal objects must be able to move from place to place given a specified type of terrain A typical approach to the number of legs is to have a data member containing this value and methods to set and get it. However, not all animals travel the same way. Some walk, some fly. Could a single variable capture this? Not likely. How about having two types of animals, both derived from the animal class. This is the traditional approach. You start with animal, then have mammals, reptiles, etc. and keep creating more and more specific animals till you have all species. This leads to a huge tree which does not promote reuse.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 The problem is exacerbated when many variations are present. It is better to have a data member that indicates the type of movement the object has.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 This should be nothing new. In true object-oriented languages, everything is an object. So having objects contain objects is nothing new.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Is Agile and Design Patterns the same? Design patterns use a “design up front” approach. Agile methods, like eXtreme programming, focuses on doing things in small steps and validating as you move forward. Agile programming requires code that is changeable, and patterns result in code that is flexible. So maybe it’s not that different. I do not necessarily agree with this. I think there are similarities, but differences as well. Agile often means that you start programming without knowing the complete requirements. This has little to do with using design patterns.

CS 350 – Software Design Expanding Our Horizons – Chapter 8 Good Rules for Good Design No Redundancy: Have only one place where a rule is implemented. Readability: If your code is understandable, quality improves as does cohesion. Testability: Your code should be testable.