Object Oriented Programming & Design - Abstraction Lecture 2 John Anthony RPI - Adjunct Assistant Professor Department of Engineering and Science.

Slides:



Advertisements
Similar presentations
EDUC4417 Senior Computers Dr. Mumbi Kariuki January 28, 2004 Object-Orientation David Cuillerier.
Advertisements

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 3: Abstract Data Types.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
1 CIS601: Object-Oriented Programming in C++ Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised.
7M701 1 Software Engineering Object-oriented Design Sommerville, Ian (2001) Software Engineering, 6 th edition: Chapter 12 )
1 Chapter 1 Object-Oriented Programming. 2 OO programming and design Object-oriented programming and design can be contrasted with alternative programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Chair of Software Engineering OOSC - Lecture 4 1 Object-Oriented Software Construction Bertrand Meyer.
1 Introduction to CS Agenda Syllabus Schedule Lecture: the management of complexity.
Chapter 1 Principles of Programming and Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Abstract Data Types and Encapsulation Concepts
Introduction SWE 619. Why Is Building Good Software Hard? Large software systems enormously complex  Millions of “moving parts” People expect software.
Introduction To System Analysis and design
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
CSCI-383 Object-Oriented Programming & Design Lecture 4.
Chapter 3 Introduction to Collections – Stacks Modified
Introduction Ellen Walker CPSC 201 Data Structures Hiram College.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Abstraction CMPS Abstraction Abstraction mechanisms are techniques to deal with creating, understanding and managing complex systems Abstraction.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
Introduction to Design (and Zen) CpSc 372: Introduction to Software Engineering Jason O. Hallstrom Authorship Disclaimer. These.
Data Abstaraction Chapter 10.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Abstraction ADTs, Information Hiding and Encapsulation.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Chapter 2 Principles of Programming and Software Engineering.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Basic Characteristics of Object-Oriented Systems
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
MAITRAYEE MUKERJI Object Oriented Programming in C++
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Principles of Programming & Software Engineering
CompSci 280 S Introduction to Software Development
Data Abstraction: The Walls
Abstract Data Types and Encapsulation Concepts
Chapter 11 Object-Oriented Design
Principles of Programming and Software Engineering
Chapter 3: Using Methods, Classes, and Objects
11.1 The Concept of Abstraction
Lecture 2 of Computer Science II
Service-centric Software Engineering
Abstract Data Types and Encapsulation Concepts
CIS601: Object-Oriented Programming in C++
Introduction to Data Structure
A type is a collection of values
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Object Oriented Programming & Design - Abstraction Lecture 2 John Anthony RPI - Adjunct Assistant Professor Department of Engineering and Science

Topics What is Abstraction What is Abstraction The Lientz Study The Lientz Study Examples of Abstraction Examples of Abstraction Layered View of an Object Oriented Program Layered View of an Object Oriented Program Other Forms of Abstraction Other Forms of Abstraction Introduction to Abstract Data Types Introduction to Abstract Data Types

Abstraction A simplified description or view of something that emphasizes characteristics or purposes relevant to the user, while suppressing details that are immaterial or distracting. A simplified description or view of something that emphasizes characteristics or purposes relevant to the user, while suppressing details that are immaterial or distracting. Translated: focus on the what not the how. The most effective weapon that computing scientists have in their fight against complexity is abstraction. What is abstraction?

Remember Information Hiding? Certain details can and in many cases should remain hidden from the client… Why is this????

Part of the Answer… Bennet P. Lientz and E. Burton Swanson: Software Maintenance Management: a Study of the Maintenance of Computer Application Software in 487 Data Processing Organizations, Addison-Wesley., Readinhg (Mass.), 1980.

Examples of Abstraction Abstracts of a research papers Abstracts of a research papers Maps Maps Virtual Memory Virtual Memory The relationship between a registrant for a Race and the Register (Active). The relationship between a registrant for a Race and the Register (Active). Java.lang.String (vs. array of bytes) Java.lang.String (vs. array of bytes) etc. etc.

Layered View of an Object Oriented Program Packages Service Classes Operations Decreasing levels of abstraction 1 n 1 n 1 n Program 1 n

Layered View - Services Decreasing levels of abstraction Service (Service Oriented Architecture) Services provide network addressable, loosely coupled, and stateless operations to consumers. Network Addressable – bound to a network address (URI) and (often) published to a registry for discovery. Loosely Coupled – services exchange data and are invoked using non-proprietary technologies. Services can also be composed into other services. Stateless – the execution of a Service N does not depend on the execution of Service N-1 or Service N+1. Packages Service Classes Operations 1 n 1 n 1 n Program 1 n

Layered View - Programs Decreasing levels of abstraction Program An object oriented program is a “community” of objects that interact in order to achieve a common goal. A program is the implementation of a service. Community of Objects – The interface of a program hides the complexity of the underlying number, types, and relationships between the objects. Application Programming Interface (API) User Interface Common Goal – the program and its underlying model should solve a problem or set of like problems. Packages Service Classes Operations 1 n 1 n 1 n Program 1 n

Layered View - Packages Decreasing levels of abstraction Packages Some OOP languages support the grouping of classes into packages. Packages provide a (logical) grouping of classes while providing mechanisms for certain classes and features to be package public and package private. Packages Service Classes Operations 1 n 1 n 1 n Program 1 n Package x Class A Class B Class C Client

Layered View - Classes Decreasing levels of abstraction Classes A class is a static representation of the data and behavior of a set of objects. The public interface of a class serves as a contract to the supplier. The interface should abstract the internal implementation details of the supplier from the client. Consider: public, friendly Note: Java supports the notion of inner and anonymous classes which provides yet another level of abstraction at the class level. Class AClass B ClientSupplier Packages Service Classes Operations 1 n 1 n 1 n Program 1 n

Layered View - Operations Decreasing levels of abstraction Operations The class level is concerned with what parts of the interface should be exported or made public. Abstraction considerations can be broken down into design-time and compile-time. Compile-time Access modifier (public, protected, private, friendly) Design-time Operation Name Operation Parameters Return Values (also know as functions) Class AClass B ClientSupplier Packages Service Classes Operations 1 n 1 n 1 n Program 1 n

Other Forms of Abstraction

Encapsulation & Composition Encapsulation - A technique for hiding information within a structure. Encapsulation - A technique for hiding information within a structure. Composition – A technique for building complex structures out of simpler parts. These techniques not only provides abstraction, it also supports interchangeability. Composition – A technique for building complex structures out of simpler parts. These techniques not only provides abstraction, it also supports interchangeability. higher levels of abstraction Computer Memory CPU Bus Control Unit ALU Registers Decoder Full Adder Logical Unit Not Gate And Gate OR Gate Redesigned And Gate

Composition Example Regular Expressions - A pattern of characters used to match against the same characters in a search. They usually include special characters, which represent things other than themselves, to refine the search. TextRegular ExpressionResult Catastrophiccatcat (0,3) Catastrophiccat.cata(0.4) Catastrophic[cbz]atcat(0,3) Catastrophic6([a-z]*[^5]\b)no match

Composition Example 2 Consider building a GUI in Java. Consider building a GUI in Java. Insert picture of GUI and highlight composition

Encapsulation & Composition (con’t) Public Part Secret Part Composition Encapsulation

Inheritance The property of objects by which instances of a class can have access to data and method definitions contained in a previously defined class (the ancestor), without the definitions being restated. The property of objects by which instances of a class can have access to data and method definitions contained in a previously defined class (the ancestor), without the definitions being restated. When designing a CPU, you’d like to be able to swap in and out different scheduling algorithms without having to build in special considerations into the CPU. Scheduler Operating System FCFSSJFRR higher levels of abstraction Partial implementation higher levels of specialization

Composition vs. Inheritance How do we know when to use which strategy? How do we know when to use which strategy? Apply the “is-a” and the “has-a” test. ComponentComponentStrategy CarEnginehas-a SquarePolygonis-a FCFS Scheduler Queue has-a OR is-a ????

Interfaces Interfaces can be separated from the implementation. Interfaces can be separated from the implementation. The interface describes the “what” and the implementation describes the “how”. The interface describes the “what” and the implementation describes the “how”. public interface Stack { public void put(Object o); public Object top(); … } public class ListStack implements Stack public void put(Object o) { list.add(o); } … } Interface Implementation

Cohesion and Coupling Cohesion – the degree to which components of a single software system (such as members of a single class) are tied together. Cohesion – the degree to which components of a single software system (such as members of a single class) are tied together. Coupling – the degree to which separate software components are tied together. Coupling – the degree to which separate software components are tied together. Design goal: Systems (objects) should be highly cohesive and loosely coupled.

Poor Cohesion public abstract class Policy { private List drivers; …. /** Returns the drivers. */ public List getDrivers() { return drivers; } /** drivers The drivers to set. */ public void setDrivers(List drivers) { this.drivers = drivers; } …………. }

History of Abstraction Mechanisms opcodeOperand1Operand2 Assembly Language integer addition integer subtraction memory locations

ADDIA, X SUBI B, X Commandvar1, var2 Assembly Language (with Assembler) integer addition integer subtraction pointers

Procedures & Functions First mechanism for reuse and information hiding. However, there were still problems… …. boolean locked = false; void lock() { locked = true; } void unlock() { locked false; }….

Modules Modules - divided the name space into public and private areas. Dr. David Parnas – father of modular design. "...it is almost always incorrect to begin the decomposition of a system into modules on the basis of a flowchart. We propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others." …. private boolean locked = false; public void lock() { locked = true; } publicvoid unlock() { public void unlock() { locked false; }….

Abstract Data Types The notion of an ADT was driven by two important goals: The notion of an ADT was driven by two important goals: 1. The need to define new data types (beyond the primitives supported by the language). 2. The need to use the features of an ADT without being exposed to the underlying implementation. An Abstract Data Type (ADT) is an abstract specification that defines the data types and operations independent of the implementation.

Abstract Data Types (con’t) Every ADT must contain 4 paragraphs: 1. Types 2. Functions 3. Axioms 4. Preconditions

The Stack ADT The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item on the stack, a method to test for whether the stack is empty, and a method to search the stack for an item and discover how far it is from the top.

Types The types paragraph lists the types introduced into the specification. The types paragraph lists the types introduced into the specification. This specification is about a single abstract data type Stack, describing stacks of objects of type Object. Stack [Object] Types

Functions The functions paragraph lists the operations applicable to instances of the ADT. The functions paragraph lists the operations applicable to instances of the ADT. push: Stack[Object]  Object pop: Stack[Object]  Object peek: Stack[Object]  Object empty: Stack[Object]  boolean Functions

The functions paragraph described the signatures of the functions but it did not define the functions. As such, we do not have a Stack (LIFO) yet. Functions (con’t)

Axiomatic Definitions Each axiom must hold for all instances s of type Stack and all elements x of type Object. Axioms For any x:Object, s:Stack[Object], A1: peek (push (x) ) = x A2: pop (push (x) ) = s A3: empty (new) A4: not empty (push(s, x)) A1: tells us that the top element of the stack is the last element pushed A2: tells us that removal of the top element returns the stack to the state it had before the last push A3: tells us that a newly created stack is empty A4: tells us that pushing an entity on a stack results in a nonempty stack

??? Are we satisfied with our specification?

Preconditions Since ADTs may contain partial functions, preconditions are stated in order to avoid errors. The precondition of an operation is a logical assertion that specifies the assumptions about and the restrictions upon the values of the arguments of the operation. If the precondition of an operation is false, then the operation cannot be safely applied. If any operation is called with its precondition false, then the program is incorrect.

Preconditions (con’t) Preconditions pop (s: Stack [Object]) required not empty (s) peak (s: Stack [Object]) required not empty (s)

Complete ADT Specification of Stacks Stack [Object] Types push: Stack[Object]  Object pop: Stack[Object]  Object peek: Stack[Object]  Object empty: Stack[Object]  boolean Functions Axioms For any x:Object, s:Stack[Object], A1: peek (push (x) ) = x A2: pop (push (x) ) = s A3: empty (new) A4: not empty (push(s, x)) pop (s: Stack [Object]) required not empty (s) peak (s: Stack [Object]) required not empty (s) Preconditions

Implementing an ADT Public Part ADT Specification Secret Part choice of representation implementation of functions Types, Functions, Axioms, and Preconditions Vector public Object pop() { Object x = null; if(! empty()) { x = this.firstElement; this.removeElementAt(0); } else {…} return x; }