Overview. OOP: model, map, reuse, extend. Examples of objects. Introduction to Object Oriented Design

Similar documents
The Final Exam Paper. Duration: 2 hours Reading: 15 minutes Total marks: 65 Hurdle: 32.5

1. Write two major differences between Object-oriented programming and procedural programming?

CHAPTER 5 GENERAL OOP CONCEPTS

Object oriented programming Concepts

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

What are the characteristics of Object Oriented programming language?

Java Object Oriented Design. CSC207 Fall 2014

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

Inheritance and Encapsulation. Amit Gupta

Inheritance and Polymorphism

What is a Programming Paradigm

Object-Oriented Programming in C++/Handout 01 Page 1 of 8

Data Structures (list, dictionary, tuples, sets, strings)

OBJECT ORIENTED PROGRAMMING

Introduction to Object-Oriented Programming

ITI Introduction to Computing II

Elementary Concepts of Object Class

Inheritance, and Polymorphism.

ITI Introduction to Computing II

Object Orientated Analysis and Design. Benjamin Kenwright

SEEM4570 System Design and Implementation. Lecture 11 From Design to Implementation

Goals of the Lecture OO Programming Principles

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

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

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Data Structures (INE2011)

Data Abstraction. Hwansoo Han

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

SEEM4570 System Design and Implementation Lecture 09 Object Oriented Programming

Classes. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java.

Object Oriented Programming. Java-Lecture 11 Polymorphism

BASIC CONCEPT OF OOP

Object Oriented Software Development CIS Today: Object Oriented Analysis

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

Computer Science 4U Unit 1. Programming Concepts and Skills Modular Design

Object Oriented Programming. Michał Bereta

MechEng SE3 Lecture 7 Domain Modelling

Inheritance. OOP: Inheritance 1

Inheritance CSC 123 Fall 2018 Howard Rosenthal

What is Inheritance?

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Get Unique study materials from

OO Techniques & UML Class Diagrams

CS304 Object Oriented Programming Final Term

Object Oriented Programming

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Software Design and Analysis for Engineers

Inheritance and Interfaces

Object Oriented Programming using C++

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.


CS-202 Introduction to Object Oriented Programming

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Basics of Object Oriented Programming FCITR MAGAZINE DR. SHAKEEL AHMAD

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018)

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

Inheritance and Substitution (Budd chapter 8, 10)

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

CS111: PROGRAMMING LANGUAGE II

Lecture 3 More OOP. CS 2113 Software Engineering Tim Wood. The George Washington University

Object Oriented Programming with JAVA

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

8. Polymorphism and Inheritance

Object oriented Programming

Lecture 7: Classes and Objects CS2301

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

OBJECT ORİENTATİON ENCAPSULATİON

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin

Programming in C# Inheritance and Polymorphism

ECE 122. Engineering Problem Solving with Java

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

G Programming Languages - Fall 2012

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

PROGRAMMING LANGUAGE 2

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

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

UML Primer. -Elango Sundaram

Topics. Modularity and Object-Oriented Programming. Dijkstra s Example (1969) Stepwise Refinement. Modular program development

PROGRAMMING IN C++ COURSE CONTENT

Topics in Object-Oriented Design Patterns

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Computer Science II (20073) Week 1: Review and Inheritance

Structured Programming

CSE 307: Principles of Programming Languages

Inheritance, Polymorphism, and Interfaces

Babu Madhav Institute of Information Technology 2016

CSC 1214: Object-Oriented Programming

Object-Oriented Design

Introduction to OO Concepts

Object Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani

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

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Syllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE1303. B.Tech. Year - II

Object Oriented Programming: Based on slides from Skrien Chapter 2

Information System Design (IT60105)

Transcription:

Overview Introduction to Object Oriented Design Understand Classes and Objects. Understand some of the key concepts/features in the Object Oriented paradigm. Benefits of Object Oriented Design paradigm. 1 2 OOP: model, map, reuse, extend Examples of Objects Model the real world problem to user s perceive; Use similar metaphor in computational env. Construct reusable components; Create new components from existing ones. CAR VDU BOY BOOK GIRL TREE CLOCK TRIANGLE Figure 1.9: Examples of objects 3 4 Classes: Objects with the same attributes and behavior Object Oriented Paradigm: Features Person Objects Abstract Into Person Class Attributes: Name, Age, Sex Operations: Speak(), Listen(), Walk() Single Inheritance Vehicle Objects Abstract Into Vehicle Class Attributes: Name, Model, Color Operations: Start(), Stop(), Accelerate() OOP Paradigm Polygon Objects Delegation Abstract Into Polygon Class Attributes: Vertices, Border, Color, FillColor Operations: Draw(), Erase(), Move() Genericity Multiple Inheritance Figure 1.12: Objects and classes 5 6

Java s OO Features OOP Paradigm Single Inheritance Java OOP Paradigm Single Inheritance It associates the code and the data it manipulates into a single unit; and keeps them safe from external interference and misuse. Delegation Delegation Genericity Genericity Data Multiple Inheritance 7 Multiple Inheritance Functions 8 Abstract Data Type (ADT) OOP Paradigm Single Inheritance Delegation The technique of creating new data types that are well suited to an application. It allows the creation of user defined data types, having the properties of built data types and a set of permitted operators. In Java, partial support. A structure that contains both data and the actions to be performed on that data. Class is an implementation of an Abstract Data Type. Genericity Multiple Inheritance In C+ +, fully supported (e.g., operator overloading). 9 10 Class- Example Class class Account { private String accountname; private double accountbalance; Class is a set of attributes and operations that are performed on the attributes. public withdraw(); public deposit(); public determinebalance(); // Class Account Account accountname accountbalance withdraw() deposit() determinebalance() Student name age studentid getname() getid() 11 12

Objects Classes/ Objects An Object Oriented system is a collection of interacting Objects. Student :John :Jill John and Jill are objects of class Student Object is an instance of a class. :circlea :circleb circlea and circleb are objects of class 13 14 Class A class represents a template for several objects that have common properties. A class defines all the properties common to the object - attributes and methods. A class is sometimes called the object s type. Object Objects have state and classes don t. John is an object (instance) of class Student. name = John, age = 20, studentid = 1236 Jill is an object (instance) of class Student. name = Jill, age = 22, studentid = 2345 circlea is an object (instance) of class. = (20,10), = 25 circleb is an object (instance) of class. = (0,0), = 10 15 16 - Example All information (attributes and methods) in an object oriented system are stored within the object/ class. Information can be manipulated through operations performed on the object/ class interface to the class. Implementation is hidden from the user. Object support Information Hiding Some attributes and methods can be hidden from the user. class Account { private String accountname; private double accountbalance; public withdraw(); public deposit(); public determinebalance(); // Class Account messag e Deposit Account balance message Withdraw Determine Balance message 17 18

Abstraction - Example The technique of creating new data types that are well suited to an application. It allows the creation of user defined data types, having the properties of built in data types and more. class Account { private String accountname; private double accountbalance; public withdraw(); public deposit(); public determinebalance(); // Class Account Creates a data type Account Account acctx; 19 20 Inheritance New data types (classes) can be defined as extensions to previously defined types. Parent Class (Super Class) Child Class (Sub Class) Subclass inherits properties from the parent class. Parent Child Inherited capability Inheritance - Example Example Define Person to be a class A Person has attributes, such as age,, gender Assign values to attributes when describing object Define student to be a subclass of Person A student has all attributes of Person, plus attributes of his/her own ( student no, course_enrolled) A student has all attributes of Person, plus attributes of his/her own (student no, course_enrolled) A student inherits all attributes of Person Define lecturer to be a subclass of Person Lecturer has all attributes of Person, plus attributes of his/her own ( staff_id, subjectid1, subjectid2) 21 22 Inheritance - Example Class can be a subclass (inherited from ) of a parent class - Inheritance - Example Inheritance can also have multiple levels. Graphic 23 24

Uses of I nheritance - Reuse Uses of I nheritance - Reuse If multiple classes have common attributes/methods, these methods can be moved to a common class - parent class. This allows reuse since the implementation is not repeated. Example : and method have a common method move(), which requires changing the coordinate. { = newcentre; { = newcentre; 25 26 Uses of I nheritance - Reuse Uses of I nheritance - Specialization Specialized behavior can be added to the { = newcentre child class. In this case the behaviour will be implemented in the child class. E.g. The implementation of method in the class is different from the class. method in the child classes override the method in parent classes(). 27 28 Uses of I nheritance - Specialization Uses of I nheritance - Specialization ; - Not implemented And left for the child classes To implement { return pi* r^ 2; { return * ; { return pi* r^ 2; { return * ; 29 30

Uses of I nheritance Common Interface All the operations that are supported for and are the same. Some methods have common implementation and others don t. move() operation is common to classes and can be implemented in parent., operations are significantly different and have to be implemented in the respective classes. The class provides a common interface where all 3 operations move(), and. Uses of I nheritance - Extension Extend functionality of a class. Child class adds new operations to the parent class but does not change the inherited behavior. E.g. class might have a special operation that may not be meaningful to the class - rotate90degrees() 31 32 Uses of I nheritance - Extension Uses of I nheritance Multiple I nheritance Inherit properties from more than one class. This is called Multiple Inheritance. Graphics rotate90degrees() 33 34 Uses of Multiple Inheritance Uses of I nheritance Multiple I nheritance This is required when a class has to inherit behavior from multiple classes. In the example class can inherit move() operation from the class and the paint() operation from the Graphics class. Multiple inheritance is not supported in JAVA but is supported in C+ +. Graphic color paint() 35 36

Polymorphic which means many forms has Greek roots. Poly many Morphos - forms. In OO paradigm polymorphism has many forms. Allow a single object, method, operator associated with different meaning depending on the type of data passed to it. An object of type or can be assigned to a object. The behavior of the object will depend on the object passed. circlea = new (); Create a new circle object shape = circlea; shape.; method for circle class will be executed rectanglea = new (); Create a new rectangle object shape= rectangle; shape. method for rectangle will be executed. 37 38 Method Overloading Operator Overloading Multiple methods can be defined with the same name, different input arguments. Method 1 - initialize(int a) Method 2 - initialize(int a, int b) Appropriate method will be called based on the input arguments. initialize(2) Method 1 will be called. initialize(2,4) Method 2 will be called. Allows regular operators such as +, -, *, / to have different meanings based on the type. E.g. + operator for can re-defined c = c + 2; Not supported in JAVA. C+ + supports it. 39 40 The phenomenon where the object outlives the program execution. Databases support this feature. In Java, this can be supported if users explicitly build object persistency using IO streams. Why OOP? Greater Reliability Break complex software projects into small, self-contained, and modular objects Maintainability Modular objects make locating bugs easier, with less impact on the overall project Greater Productivity through Reuse! Faster Design and Modelling 41 42

Benefits of OOP.. Inheritance: Elimination of Redundant Code and extend the use of existing classes. Build programs from existing working modules, rather than having to start from scratch. Æ save development time and get higher productivity. : Helps in building secure programs. Benefits of OOP.. Multiple objects to coexist without any interference. Easy to map objects in problem domain to those objects in the program. It is easy to partition the work in a project based on objects. The Data-Centered Design enables us in capturing more details of model in an implementable form. 43 44 Benefits of OOP.. Summary Object Oriented Systems can be easily upgraded from small to large systems. Message-Passing technique for communication between objects make the interface descriptions with external systems much simpler. Software complexity can be easily managed. Object Oriented Design, Analysis, and Programming is a Powerful paradigm Enables Easy Mapping of Real world Objects to Objects in the Program This is enabled by OO features: Inheritance Standard OO Design (UML) and Programming Languages (C++ /Java) are readily accessible. 45 46 Reference Chapter 1: Programming with Java by Balagurusamny Optional: Chapter 1: Mastering C+ + by V. Rajuk and R. Buyya, Tata McGraw Hill, New Delhi, India. 47