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

Similar documents
CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Object Orientated Analysis and Design. Benjamin Kenwright

OVERRIDING. 7/11/2015 Budditha Hettige 82

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

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

C++ Important Questions with Answers

ITI Introduction to Computing II

Chapter 5 Object-Oriented Programming

ITI Introduction to Computing II

Midterm Exam 5 April 20, 2015

Inheritance and Polymorphism

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

CS-202 Introduction to Object Oriented Programming

Java Fundamentals (II)

Basics of Object Oriented Programming. Visit for more.

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

What are the characteristics of Object Oriented programming language?

Inheritance -- Introduction

Object Oriented Programming: Based on slides from Skrien Chapter 2

Sorting. Sorting. Selection sort

QUESTIONS FOR AVERAGE BLOOMERS

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

Object Oriented Programming. Java-Lecture 11 Polymorphism

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

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

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

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

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

CS111: PROGRAMMING LANGUAGE II

Object oriented programming Concepts

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

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

Sri Vidya College of Engineering & Technology

The Essence of Object Oriented Programming with Java and UML. Chapter 2. The Essence of Objects. What Is an Object-Oriented System?

OBJECT ORIENTED PROGRAMMING

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

OBJECT ORIENTED SIMULATION LANGUAGE. OOSimL Reference Manual - Part 1

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

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

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

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

Object-Oriented Programming

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

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

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

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

Chapter 6 Reflection

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Inheritance and Polymorphism

Inheritance and Polymorphism

PROGRAMMING LANGUAGE 2

Java Object Oriented Design. CSC207 Fall 2014

Programming Exercise 14: Inheritance and Polymorphism

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

Inheritance. Chapter 7. Chapter 7 1

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

COP 3330 Final Exam Review

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

An Introduction to Object Orientation

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

Object-Oriented Programming (OOP) Fundamental Principles of OOP

8. Polymorphism and Inheritance

Java: introduction to object-oriented features

Object-Oriented Design

Chapter3: Introduction to Classes and Objects

Programming II (CS300)

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

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

CS 251 Intermediate Programming Inheritance

INHERITANCE. Spring 2019

Object-Oriented Programming

Introduction to Programming Using Java (98-388)

Data Abstraction. Hwansoo Han

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

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

Part 7 - Object Oriented Concepts Classes, Objects, Properties and Methods

Inheritance and object compatibility

Class object initialization block destructor Class object

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Chapter 5. Inheritance

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Inheritance, Polymorphism, and Interfaces

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

CMSC 132: Object-Oriented Programming II

Chapter 1: Object-Oriented Programming Using C++

Object-Oriented Concepts and Design Principles

Super-Classes and sub-classes

ECE 122. Engineering Problem Solving with Java

CSCE3193: Programming Paradigms

Inheritance. Transitivity

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

Inheritance, and Polymorphism.

CMSC202 Computer Science II for Majors

OOAD - OBJECT MODEL. The concepts of objects and classes are intrinsically linked with each other and form the foundation of object oriented paradigm.

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

Transcription:

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Sung Hee Park Department of Mathematics and Computer Science Virginia State University September 18, 2012

The Object-Oriented Paradigm Class A Class B Class C Class D Instance Variables Instance Variables Instance Variables Instance Variables Instance Methods Instance Methods Instance Methods Instance Methods Instanciation Object Object Object Object Object Object Object Object Interactions among objects take place via message passing

Objects An object is an entity which has a state and a defined set of operations which operate on that state. The state is represented as a set of object attributes. The operations associated with the object provide services to other objects (clients) which request these services when needed. Objects are created according to some object class definition. An object class definition serves as a template for objects. It includes declarations of all the attributes and services which should be associated with an object of that class.

Classes A class is a grouping or categorization of objects with the same characteristics, services, and behaviors. A class may be extended into other classes. Extending a class is called subclassing and an extended class is called a subclass. A subclass inherits all the characteristics, services, and behaviors of the parent class. It customizes what it inherits and/or provides more characteristics, services, or behaviors. The parent of a subclass is called the superclass. The class at the top level (having no superclass) is called the root class.

Instantiation Creation of an object belonging to a class is called instantiation. The new object inherits all characteristics (instance variables) and behaviors (instance methods) specified in the class from which it is instantiated. Instance variables of a class are created for each object instantiated as a member of that class. Instance methods are inherited, but no method code is replicated.

Variables (Attributes) Characteristics (attributes) of an object are represented by variables. Typically three kinds of variables exist: class variables, instance variables, and local variables. Class Variables are attributes of a class and are declared in the class for use by the methods of that class and its subclasses and by the objects instantiated from that class and its subclasses. Instance Variables, declared in a class, are used by the instance methods of that class and are created for each object instantiated as belonging to that class or any of its subclasses, i.e., for each instance of a class, and hence the designator instance. Local Variables are declared within a method for use only during the execution of that method. On completion of a method, all local variable values are lost. Example variables can have the following data types: boolean, character, class reference, object reference, integer number, real number, enumeration.

Methods (Services) Services provided and behaviors exhibited by an object are specified in methods. Two types of methods exist: class methods and instance methods. Class Methods are used to provide services specific to a class. For example, the method new which creates an instance of a class. Instance Methods, given in a class, are used to specify the services provided and behavior exhibited for each object instantiated from that class. Each instance (i.e., instantiated object) created as belonging to a class provides the services and behavior specified in the instance methods of that class. The method code is specified only once in the class and is not replicated for each instantiation of an object from that class.

Inheritance Vehicle Car Motor Cycle Sedan Van Truck When an object is declared as member of a class, itinherits the characteristics (instance variables) and behaviors (instance methods) of that class as well as the characteristics and behaviors of that class's superclass, and any ancestral classes, tracing back to the root class. Inheritance significantly facilitates reusability of earlier developed classes and decreases software development time.

Message Passing All instantiated objects communicate with each other via message passing. Sending a message to an object implies the invocation of one of the receiving object's methods. Generally, it is said that send message M to object A as opposed to send a message to object A to invoke its method M. Objects are identified by their unique addresses internally maintained by the implementation programming language. They are called object references. An object reference uniquely identifies the object which will receive the message.

Encapsulation Encapsulation means that a consumer sees only the services that are available from an object, but not how those services are implemented. Consumer / Supplier Viewpoints Only the supplier has visibility into the object s procedures and data. From a consumer s point of view, an object is a seamless capsule that offers a number of services, with no visibility as to how these services are implemented.

Polymorphism (Override) Vehicle Car Motor Cycle Sedan Van Truck Polymorphism refers to the ability of an object to assume more than one form. For example, an object reference can be created to refer to an automobile: obj ref automobile; The object reference shape may refer to a sedan, van, or truck depending on the logic at run time. For example, sending the computemilepergallon message to the object pointed to by the object reference automobil would invoke a different algorithm (procedure) depending on the form of that object, i.e., sedan, van, or truck, at run time.

Example of Override and Overload in Java public class Car{ private int _id = 0; public int Id { get { return _id; } set { _id = value; } } private string _name = string.empty; public string Name { get { return _name; } set { _name = value; } } public class Sedan : Car{ private string _testcolor = string.empty; public string TestColor { get { return _testcolor; } set { _testcolor = value; } } public string computemilepergallon() {//Overrided method } return base.testmethod() + " World"; /Overrided method } public virtual string computemilepergallon() { return " Hello"; } //Overloaded method Add } public int Add(int num1, int num2) //Overloaded method Add { } public int Add(int num1, int num2, int num3) { }

Dynamic Binding Dynamic Binding implies that the implementation code executed in responding to a particular message in the source code is not known at compile time, and is dispatched at run time depending on the form of the polymorphic object that receives the message. For example, an object reference can be created to refer to an automobile: obj ref automobile; The object reference automobile may refer to, or can assume the form of, a sedan, van, or truck. For example, sending the computempg message to an object of the Sedan class, pointed to by the object reference automobile, would invoke a different algorithm from one invoked when sending computempg to an object of the Truck class, again pointed to by the object reference automobile. Therefore, the implementation code executed in response to the computempg message is determined and dynamically bound at run time depending on the form of the object, pointed to by the object reference automobile, which receives the message. Polymorphism and dynamic binding are strongly related.

Association is managed by Employee is a member of Department manages Manager Objects and object classes participate in relationships with other objects and object classes. In the UML, a generalized relationship is indicated by an association. Associations may be annotated with information that describes the association. Associations are general but may indicate that an attribute of an object is an associated object or that a method relies on an associated object.

Consumer / Supplier Viewpoints A producer or consumer of date Examples: a person, a device, a sensor Another example: computer-based system Data must always originate somewhere and must always be sent to something

Process A data transformer (changes input to output) Examples: compute taxes, determine area, format report, display graph Data must always be processed in some way to achieve system function

Data Flow Data flows through a system, beginning as input and be transformed into output. base height compute triangle area area

Data Stores

Control Flow Diagrams Represents events and the processes that manage events. A Control Specification can be given in the form of: state diagram state transition table decision tables activation tables