An Introduction to Object Orientation

Similar documents
Rushikesh K Joshi. Department of Computer Science and Engineering Indian Institute of Technology Bombay

CSE 70 Final Exam Fall 2009

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design Pattern and Software Architecture: IV. Design Pattern

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Object Orientated Analysis and Design. Benjamin Kenwright

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Inheritance. Transitivity

Inheritance, and Polymorphism.

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

What are the characteristics of Object Oriented programming language?

SDC Design patterns GoF

JAVA: A Primer. By: Amrita Rajagopal

ITI Introduction to Computing II

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

ITI Introduction to Computing II

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

2. The object-oriented paradigm

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CS 251 Intermediate Programming Inheritance

Data Abstraction. Hwansoo Han

administrivia today UML start design patterns Tuesday, September 28, 2010

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Chapter 1: Object-Oriented Programming Using C++

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

Design Patterns: State, Bridge, Visitor

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Object- Oriented Design with UML and Java Part I: Fundamentals

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

OO Frameworks. Introduction. Using Frameworks

Object-Oriented Design

Comp-304 : Object-Oriented Design What does it mean to be Object Oriented?

Object Oriented Paradigm

The Design Patterns Matrix From Analysis to Implementation

The object-oriented approach goes a step further by providing tools for the programmer to represent elements in the problem space.

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

Chapter 14 Abstract Classes and Interfaces

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation

Object Oriented Programming. Java-Lecture 11 Polymorphism

Reuse at Design Level: Design Patterns

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns

C++ Inheritance and Encapsulation

Design Patterns. (and anti-patterns)

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

UNIT I. 3. Write a short notes on process view of 4+1 architecture. 4. Why is object-oriented approach superior to procedural approach?

Object-oriented Programming. Object-oriented Programming

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Java Object Oriented Design. CSC207 Fall 2014

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Subclasses, Superclasses, and Inheritance

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

2D1358 Object Oriented Program Construction in C++ Exercises & Labs. Course Registration / Accounts. Course Literature

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Rushikesh K Joshi. Department of Computer Science and Engineering Indian Institute of Technology Bombay

G Programming Languages - Fall 2012

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Software Architecture

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

Introduction to Object-Oriented Programming

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Programming, numerics and optimization

New Programming Paradigms

Concepts of Object-Oriented Programming. Richard Berger Johannes Kepler University Linz

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D)

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

Object Orientation. Chapter Sixteen Modern Programming Languages, 2nd ed. 1

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Example: Count of Points

Class and Functions. Reusable codes

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

PROGRAMMING IN C++ COURSE CONTENT

Inheritance, Polymorphism and the Object Memory Model

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

Object-Oriented Concepts and Design Principles

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

CS201 - Introduction to Programming Glossary By

Introduction to Software Engineering: Object Design I Reuse & Patterns

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Basic Object-Orientation

Transcription:

An Introduction to Object Orientation Rushikesh K Joshi Indian Institute of Technology Bombay rkj@cse.iitb.ac.in A talk given at Islampur

Abstractions in Programming Control Abstractions Functions, function calls, recursion Assignment statement Sequential execution If then else, while, repeat, case, for statements Threads Coroutines Contiuations and mobility Rules and inference Control abstractions can control data flows

Abstractions in Programming Data Abstractions symbols and lists Types: int, bool, char, float.. Structures Unions, enumerated types Arrays, Vectors operations supported on data abstractions are mostly general: read, write

Towards Richer Abstractions The above control and data abstraction are low level High level abstractions need to be composites of these Besides function composition, structures: it makes sense to combine data and control together to form an interesting composite abstraction

Examples of Richer Abstraction File at OS level Data: stream of bytes Operations supported: open, close, read, write, rewind, seek Process at OS level Data: control and data segments, page tables, open files, priority.. Control: create, terminate, suspend, resume, trace Stack Data structure Data: elements arranged in the form of stack Control: create, delete, push, pop, top Table in a spreadsheet/gui Data: rows, columns, content Operations (control): create, delete, add/del row/column, insert element Name server Data: name-location bindings arranged in a hierarchy Operations: add new binding, delete existing binding, create/delete namespaces

Compare These with Some Examples of Abstraction in Real life Fan Data: motor, capacitor.. Tape Operations: switch on, off, set speed Data: internal circuits, cassette holder Operations: switch on/of, open/close cassette holder, play, rewind, forward, record, pause, continue It s a composite object: player/recorder + cassette holder Washing Machine, car, scooter, TV set, mixer

They have something in common: Towards Object Abstractions It is convenient to think of abstractions in terms of the data that they possess along with the operations which they allow on them Data: Internal Operations: Expose for External Use User only worries about how to use an abstraction but now how it is implemented Such simplicity at high level is possible due to Thinking data and high level control together Separating data from exposable operations on them Hiding data from external environment

Two Basic Principles of Object Orientation Abstraction Object abstraction: data + observable behavior Encapsulation Only observable behavior is exposed, the rest (mainly the data) is hidden from external environment

Exercise Define following objects in terms of their observable behavior Stack List Account Button Transaction Semaphore

Object Orientated Programming Languages Provide a core abstraction for defining such objects Class and instances: class based languages Only instances: prototyped based languages In addition to the core object abstraction, the benefits of object orientations are reaped through two additional principles of inheritance and polymorphism through inheritance

A Class and its implementation Class X { int x; public: }; int add(int p); int subtract(int p); Int X:: add (int p) {x=x+p;}; Int X::subtract (int p) {x=x-p;};

Another Example class Complex { private: int i ; // real component int j ; // imaginary component public: Complex (int x, int y) { i=x; j=y; } void add (Complex a) ; void printstate (void); }; void Complex::add(Complex) { i += a.i ; j += a.j; } Void Complex :: printstate (void) { cout << i << " + j" << j << "\n" ; }

Inheritance Mechanism for Pure Extension C1={f,g,h} C2=C1+{p,q} Specialization C1={f,g,h} C2=C1 with f to be treated as f, rest of o1 as it is+{p,1} Polymorphism Use instances of C2 where instances of C1 are required

An Example of Inheritance Hierarchy shape Circle Rectangle Triangle

Exercise Implement classes shape, circle, rectangle and triangle to support following abilities for all shapes: Create, delete, move, clone What do you keep in the superclass? For use at it is For specialization and subsequent polymorphism

An Application that uses this hierarchy: A Graph Drawing Editor

Benefits of inheritance Superclass Shape contains most common properties It also contains abstract member functions which are applicable to all shapes Abstract member functions are concretely defined in subclasses Application has a lot of code written in terms of superclass shape

Using Polymorphism Mouselistner (event e, shape s) { if (e==drag) } smoveto (currentx, currenty); The above code is applicable to all types of shapes. In absence of polymorphism, a switch statement had to be used

Dynamic Binding of method dispatches results in Polymorphism Mouselistner (event e, shape s) { if (e==drag) } smoveto (currentx, currenty); The moveto method bound at runtime S is supertype (static type), but actual object s type (dynamic type) determines which member function should be dispatched

Abstract Superclasses Meant for specialization only Not for instantiation directly Represent most common behavior for all its subclasses E.g. class shape in above example All methods are unimplemented (pure virtual in C++/Java)

Hooks, Template Methods and Concrete Methods Class X { public: }; f()=0; //hook g() {..; f();.;} h () {...}.// concrete method // template method Frameworks/Design Patterns use these three meta-patterns extensively

Terminologies Class Instance/Object Implementation Interface Information/Data hiding Encapsulation Inheritance Superclass/Base class Subclass/Derived Class

Contracts Between class and itself Can see all its data and member function Between class and its external environment Environment sees only public member functions/public data Between class and its subclasses Subclasses get to see protected members

Purity of Object Orientation C++ Supports object oriented but does not enforcing Functions which are non-member functions are acceptable Encapsulation can be broken Java Enforces classification Eiffel Even main is a member function Design on the basis of contracts Smalltalk Even control constructs are object oriented Classes are also instances

Tree Vs. Forest Most common superclass for all objects in the language Class Object In smalltalk, Java Class hierarchies are not implicitly linked As in C++

Template classes Vs. Using class Object For writing generic code A generic code is applicable to different types C++ Employees template classes Java relies on super-most generic Class Object

Bytecodes for Portability of Programs Intermediate language Bytecode interpreter is made available for a specific OS Used in interpreter based OO languages such as Smalltalk and Java High Level Code compile Bytecode Bytecode Interpreter Operating System

Core Language and Libraries Core language contains set of keywords and its control, data and object abstractions Some languages also supports abilities such as treads and interprocess communication Most of the application development relies on the library/package support that the language development environments support Gui, database connectivity, distribution and component orientation, strings, collections, patterns, i/o etc.

Distributed Objects Network

Interoperability C++ object C++ object Network Java object Fortran Module Common language bridge

Design Patterns Commonly occurring non-trivial designs Collection of classes connected in a specific configuration Creational patterns Singleton, factory, prototype Structural patterns Proxy, adapter Behavioral patterns Strategy, visitor, observer, chain of responsibility

Object Oriented Analysis and Design Methods How to capture requirements? Use cases How to identify objects? Coad and Yourdon method CRC of Kent beck How to represent designs? Static behaviors Class diagrams Dynamic behavior Interaction diagrams, state diagrams, activity diagrams, collaboration diagrams Deployment/Packaging Behavior Package diagrams Deployment diagrams (machines and component allocations) Modeling Languages: e.g. UML

Some Recent Developments Software Architectures Architectural description languages Architecture to realization mappings Model Driven Architectures Component Technologies and Web Services Aspect Orientation and Advanced separation of concerns