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

Similar documents
A201 Object Oriented Programming with Visual Basic.Net

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

Chapter 5 Object-Oriented Programming

CHAPTER 5 GENERAL OOP CONCEPTS

What are the characteristics of Object Oriented programming language?

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

Object Oriented Programming with c++ Question Bank

I101/B100 Problem Solving with Computers

2.4 Structuring programs

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

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

Chapter 8: Class and Method Design

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

BASIC CONCEPT OF OOP

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

Lecture 1. Abstraction

AOSA - Betriebssystemkomponenten und der Aspektmoderatoransatz

Elementary Concepts of Object Class

From Module To Objects

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

C++ Important Questions with Answers

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

Advanced Database Applications. Object Oriented Database Management Chapter 13 10/29/2016. Object DBMSs

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

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is a Programming Paradigm

There are three basic elements in object oriented programming: encapsulation, inheritance and polymorphism.

CGS 2405 Advanced Programming with C++ Course Justification

Polymorphism Part 1 1

The major elements of the object-oriented model

Inheritance and Polymorphism

OBJECT ORIENTED PROGRAMMING

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Sri Vidya College of Engineering & Technology


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

Chapter 8: Creating Your Own Type Classes

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

Chapter3: Introduction to Classes and Objects

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

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

Object Model. Object Orientated Analysis and Design. Benjamin Kenwright

Object oriented programming Concepts

PROGRAMMING LANGUAGE 2

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

Data Structures using OOP C++ Lecture 3

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

CompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards

Programmazione. Prof. Marco Bertini


CS105 C++ Lecture 7. More on Classes, Inheritance

Object Oriented Programming. Solved MCQs - Part 2

Application-Oriented System Design

Object-Oriented Concepts and Design Principles

Concepts of Programming Languages

Complexity. Object Orientated Analysis and Design. Benjamin Kenwright

Object-Oriented Programming Concepts

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

Abstraction. Abstraction

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

UML Primer. -Elango Sundaram

Absolute C++ Walter Savitch

RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING QUESTION BANK UNIT I 2 MARKS

2. The object-oriented paradigm!

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

Classes and Objects. Object Orientated Analysis and Design. Benjamin Kenwright

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

Chapter 1: Programming Principles

VALLIAMMAI ENGINEERING COLLEGE

Object-Oriented Programming

Advanced C++ Topics. Alexander Warg, 2017

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Object Oriented Design

Data Structures and Programming with C++

Basic Object-Orientation

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Design Metrics for Object-Oriented Software Systems

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

OBJECT ORİENTATİON ENCAPSULATİON

Chapter 1: Object-Oriented Programming Using C++

Downloaded from

CMSC202 Computer Science II for Majors

CHAPTER 9 DESIGN ENGINEERING. Overview

Introduction to OOP. Procedural Programming sequence of statements to solve a problem.

G Programming Languages - Fall 2012

Inheritance and Encapsulation. Amit Gupta

Inheritance and Polymorphism

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

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

EL2310 Scientific Programming

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


Java Object Oriented Design. CSC207 Fall 2014

C++ (Non for C Programmer) (BT307) 40 Hours

Inheritance and Polymorphism

Object-Oriented Programming

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

END TERM EXAMINATION

Software Architecture

Transcription:

Part 7 - Object Oriented Concepts Classes, Objects, Properties and Methods Object Orientated Paradigm... 2 Abstract Data Types (ADT) & Encapsulation... 3 Encapsulation... 5 Classes and Objects... 6 Methods and Messages... 9 Inheritance and Multiple Inheritance... 10 Specialization... 12 Extendibility... 12 Polymorphism... 12 Polymorphism and Overloading... 13 Dynamic or Late Binding (Overriding)... 14 1

Object Orientated Paradigm MODELING THE REAL WORLD! Humans natural ability to classify, generalize and create abstractions in order to model the world.! View the world as a series of entities and the interaction among them.! Problems are solved through the interaction among a number of autonomous and cooperative objects. 2

Abstract Data Types (ADT) & Encapsulation! View the Code and Data as an atomic and non-decomposable unit.! Traditional programming languages deliver modularization by the use of procedures and functions.! Object oriented languages usually implement modularization through Abstract Data Types (or objects).! An object is defined as a set of built-in and/or userdefined data types along with a set of operations which manipulate them. ADT = Data + Code! The functions which surround the data structure provide a robust interface to the clients of that data. Code or Method Code or Method Code or Method Data or Property Code or Method Code or Method Object! Simplifies the debugging, maintenance and testing.! The applications or clients which use object will not be effected by the possible changes in the implementation of the object, as long as the interface or behavior of the object remains constant.! ADT's and Encapsulations, makes large projects intellectually manageable. 3

Encapsulation! ADT's provide a "LOGICAL" view for encapsulation, however, in a traditional programming approach one may inadvertently bypass ADT boundaries and access a given data structure, therefore, introducing potential errors.! Encapsulation provides the "PHYSICAL" method for ensuring ADT boundaries are not breached, therefore, preventing the client from unauthorized access.! Encapsulation is achieved by tightly coupling the data structure and its related methods (functions) hence viewing them as an atomic unit.! Access to the data is only possible through the public interface provided. Encapsulation hides the details of the object from the client. 4

Classes and Objects Definitions of a Class: 1) A set of similar objects. 2) The term used to define abstract data types in object oriented programming languages.! A class provides the mechanism for syntactically expressing the semantics of encapsulation. 6444444444444444444444444444444444444444444444444444447 6444=4444444444444444444444444444444444444444444444444447 5 5 class CLASS_NAME 5 5 5 { 5 5 5 private 5 5 5 variables W47 5 5 5 data structure :4444U Instance Variables5 5 5... 5 5 5 5 W48 5 5 5 public W47 5 5 5 code 5 5 5 5 method names :4444U Methods 5 5 5... 5 :48 5 } W48 5 944444444444444444444444444444444444444444444444444444448 5

Public Class CAR ' Private Data Private color As Integer Private year As Integer Private model As String Private make As String ' Public Methods Public Sub PrintColor() 'return the color attribute Console.WriteLine("The Color = {0}", color) End Sub Public Sub SetColor(ByVal clr As Integer) color = clr End Sub End Class Module Module1 Sub Main() Const BLUE As Integer = 7 Const BLACK As Integer = 3 Dim MyCar As CAR MyCar = New CAR MyCar.SetColor(BLUE) MyCar.PrintColor() Console.WriteLine(MyCar.color) Console.ReadLine() ' MyCar is a Reference Variable ' The NEW operator will actually allocate the memory needed for the car object. ' Note that this is a error, since we don't have direct access to the Color attribute. End Sub End Module 6

Objects and Classes! An object is an element of a given class. (i.e. A variables of that type)! An object is also called an instance of the class. EXAMPLE: 1) "ButtonQuit" is an object of type "Button". 2) "mycar" is an object of type "CAR". One may access the contents of an object (its instance variables) and change the state of this object by invoking or sending message to the object's methods. 7

Methods and Messages! The sub-programs (procedures and functions) within the object are called methods.! The process of invoking a method by its name is called sending a message to the object.! The state of an object can be inspected and modified by sending a message to one of its methods. EXAMPLE OF A MESSAGE: MyCar.SetColor(BLUE) Sends the message to object "MyCar" to invoke the "SetColor" method. 8

Inheritance and Multiple Inheritance! One of the most important aspect of object oriented systems.! A new class can inherit or reuse the behavior and structure of previously defined classes. CLASS X 5 5 5 5 V SUB-CLASS! The Sub-Classes (Derived Classes) can extend or add more functionality (i.e. methods and instance variables) to the base class. EXAMPLE OF A SUPER_CAR: class SUPER_CAR Inherits From CAR private SuperAttribute as String public sub GetSuperAttribute(ByVal Clr As Integer) public sub SetSuperAttribute(ByVal SuperAttr As String) End Class Dim BatMobil As SUPER_CAR An object of the type SUPER_CAR 9

ONE CAN ACCESS THE INHERITED DATA AND CODE AS FOLLOWS: BatMobil.SetColor(Black) BatMobil.SetSuperAttribute("Goes Real Fast!!").))0)))-.)))))))0)))))))- R R Object Method Name Name T T.))))))))))))))))))))))0))))))))))))))))))))))- R Message! Inheritance is a natural tool to express relationships such as classification, specialization, generalization, evolution and approximation. 10

Option Explicit On Option Strict On Public Class CAR ' Private Data Private color As Integer Private year As Integer Private model As String Private make As String ' Public Methods Public Sub PrintColor() 'return the color attribute Console.WriteLine("The Color = {0}", color) End Sub Public Sub SetColor(ByVal clr As Integer) color = clr End Sub End Class ' The SUPER_CAR class Inherits from the CAR class ' and add extends the class by adding a new attribute ' and two new methods. Class SUPER_CAR Inherits CAR ' Inherits from the CAR class Public SuperAttribute As String Public Function GetSuperAttribute() As String Return SuperAttribute End Function Public Sub SetSuperAttribute(ByVal SuperAttr As String) SuperAttribute = SuperAttr End Sub End Class 11

Module Module1 Sub Main() Const BLUE As Integer = 7 Const BLACK As Integer = 3 Dim MyCar As CAR MyCar = New CAR ' MyCar is a Reference Variable ' The NEW operator will actually allocate the memory needed for the car object. MyCar.SetColor(BLUE) MyCar.PrintColor() 'Console.WriteLine(MyCar.color) ' Note that this is a error, since we don't have direct access to the Color attribute. Dim BatMobil As New SUPER_CAR BatMobil.SetColor(BLACK) BatMobil.SetSuperAttribute("Goes Real Fast!!") BatMobil.PrintColor() Console.WriteLine(BatMobil.SuperAttribute) 'Note that I can access SuperAttribute because it is public. End Sub End Module Console.ReadLine() 12

INHERITANCE DELIVERS THREE IMPORTANT FEATURES: 1) Specialization (deriving from a general class and making it more specific.) 2) Extendibility (extending a system by inheriting classes and adding to their functionality, so called incremental development.) 3) Polymorphism (facilitates polymorphism by allowing functions to be overloaded at different levels of the class hierarchy to achieve different objectives.) 13

Polymorphism and Overloading! Polymorphism comes form the Greek : "having many shapes".! Polymorphism allows the programmer to use the same method name to perform a give generic task on a number of different data types. For example: Dim x A integer Dim y As Double Dim z As string initialize(x) initialize(y) initialize(z)! Even though the function names in the above examples are the same, the compiler is able to select the correct version.! Conflicts are resolved by Static or early binding. During compile time, the compiler will check the type of each argument and determine which function must be called.! Overloading is not a new concept, most if not all conventional languages provide overloaded operators such as (+, -, *, /, =, etc..) as well as functions such as read(), write(), print().! Polymorphism takes this concept one step further and allows user defined methods to be overloaded for any 14

object type. 15

Dynamic or Late Binding (Overriding)! Traditional procedural languages support static or early binding, which means that the compiler resolves function calls and references during the compile and link phases.! Object oriented languages provide the advantages of dynamic or late binding which allows the messages to be bound to appropriate methods at run-time. This is implemented by means of checking the number and type of the arguments (message parameters) that are sent to the method.! The same function may be defined up and down the class hierarchy, and at each level the new definition will override the old ones. 16