1 / 34

# Introduction to Object Oriented Concepts - PowerPoint PPT Presentation

Introduction to Object Oriented Concepts. WEEK1 Asst . Prof. Dr. Senem Kumova Metin. Classification of High level Programming languages. Programming paradigm : Alternative approaches to the programming process Imperative ( Procedural ) ( Fortran , Algol , Pascal , Basic , C)

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Introduction to Object Oriented Concepts' - cybele

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### IntroductiontoObjectOrientedConcepts

WEEK1

Asst. Prof. Dr. Senem Kumova Metin

Classification of HighlevelProgramminglanguages

• Imperative (Procedural) (Fortran, Algol, Pascal, Basic, C)

• Functional(Lisp, ML)

• Declarative(Logic) (Prolog,GPSS)

• Object-Oriented (C++, Java, Scala, Smalltalk)

ProgrammingLanguages 1/2

• Imperative: The language provides statements, such as assignment statements , which explicitly change the state of the memory of the computer.

X:=X+1

• Functional: In this paradigm we express computations as the evaluation of mathematical functions.

(defun factorial (n)

(if (<= n 1)

1

(* n (factorial (- n 1)))))

The program can then be called as

(factorial 10)

ProgrammingLanguages 2/2

• Logic (Declarative): In this paradigm we express computation in exclusively in terms of mathematical logic

brother(X,Y) /* X is thebrother of Y */

:- /* iftherearetwopeople F and M forwhich*/

father(F,X), /* F is thefather of X */

father(F,Y), /* and F is thefather of Y */

mother(M,X), /* and M is themother of X */

mother(M,Y), /* and M is themother of Y */

male(X). /* and X is male */

uncle (X,Y)

:- father(F,Y), brother(X,F).

• Object-Oriented: In this paradigm we associate behavior with data-structures called " objects " which belong to classes which are usually structured into a hierarchy

Whatexactly is an object?

• An OBJECT is an identitywhichincludesbothAttributes and Behaviors

EXAMPLE -- > PERSON OBJECT

Attributes : EyeColor, Age, Height …

Behaviors : Walking, Talking, Breathing …

TheObject Model

• A OO-software system is a set of cooperating objects

• Objects have state and processing ability

• Objectsexchangemessages

ClassandObject

• A class is a collection of objects that have common properties, operations and behaviors.

• A class is a data type, objects are instances of that data type.

ObjectOrientedProgramming

• A programming paradigm that uses abstraction (in the form of classes and objects) to create models based on the real world environment.

• An object-oriented application uses a collection of objects, which communicate by passing messages to request services.

• Objects are capable of passing messages, receiving messages, and processing data.

• The aim of object-oriented programming is to try to increase the flexibility and maintainability of programs. Because programs created using an OO language are modular, they can be easier to develop, and simpler to understand after development.

ProceduralVersus OO Programming

• Programs are made up of modules, which are parts of a program that can be coded and tested separately, and then assembled to form a complete program.

• in ProceduralLanguages, modulesareprocedures

• in OO languages, mainmodulesareclassesratherthanprocedures !!

ProceduralVersus OO Programming

• In OO design, attributes and behaviors are withina single object whereas in procedural they are separated!!

• Procedural programming -> Top Down Design.

• Systematically break the problem down

into sub problems (sub procedures).

• The difficulties with procedural programming, is that software maintenance can be difficult and time consuming.

FunctionalDecomposition

ProceduralVersus OO Programming

• InproceduralLanguages data

is separatedfromprocedures

 The problem of data hiding !!

• Global Data  nonproperdesign

ProceduralVersus OO Programming: EXAMPLE

• Proceduralprogramming :

• Sendonly data overwire  A handshakingaggrementmust be in placebetweendestination & source

• OOprogramming :

• Sendtheobject in which data andoperationsthatmanipulate data areencapsulated

• Example : Web object  Browser

Whatexactly is an Object?

• Attributes = Data

• Theattributescontaintheinformationthatdifferentiatesbetweenthevariousobjects !!

Whatexactly is an Object?

• Behavior = Method

• Thebehavior is whattheobject can do !!

• Youinvoke a methodbysending a messageto it.

• Eachattributemusthave set andgetmethods

 Becauseotherobjectsshould not manipulate data withinanotherobjectdue

to data hiding

• Setter = Mutator: Changesthevalue of attribute

• Getter = Accessor : Returnsthecurrentvalue of theattribute

ObjectBehaviors: Example

Employeeandpayroll UML classdiagrams

Whatexactly is a Class?

• A class is a blueprint for an object.

• Objects can not be instantiated without a class

–> When you instantiate an object you use the class as the basis for how the object is built

Example: A Definition of a Personclass

UML classdiagram of Personclass

• Theability of an objectto not revealalltheattributesandbehaviors !!

• All of the object's data is contained and hidden in the object and access to it restricted to members of that class.

• One of the fundamental principles of OOP !!!

• Data abstraction allow programmers to hide datarepresentation details behind a(comparatively)simple set of operations (an interface)

• Whatarethebenefits??

• Programmers need to knows less about the rest of the program

• Providesfaultcontainment

• Bugs are located in independent components

• Provides a significant degree of independence of programcomponents

• Separate the roles of different programmer

Data Hiding

• Data Hiding is a majorpart of encapsulation.

• Ingood OO design, an objectsholdonlyrevealtheinterfacesthatotherobjectsmusthavetointeractwith it !!!

• Interface : Thecollection of publicbehaviorsthatprovidethecommunicationwiththeobject

• Private data supports data hiding !!

A realworldexample of InterfaceandImplementation

• RequestingObject : Toaster (requireselectricity)

• Interface : Electricaloutlet

• Implementation:Coalpoweredplantornuclearpowerplantor a localgenerator

• Object oriented programming languages allow classes to inherit commonly used state and behavior from other classes  CODE REUSE

• How to factor out the commonalities of various classes?? Find out IS-A RELATIONSHIPS

• A mammal is a vertebrate

• A dog is a mammal

• Superclass (parent) contains all the attributes and behaviors that are common to classes that inherit from it (subclasses)

Inheritance : Classification of Vertebrates

• Arrowsrepresent “is-a” relationship

Inheritance: A SimpleExample

AbstractClasses

• DictionaryDefinition of Polymorphism:

The quality of being able to assume different forms

• In the context of programming:

A program part is polymorphic if it can be used for objects of several types

• Polymorphism is tightlycoupledtoinheritance

• Ininheritancehierarchy, allsubclassesinherittheinterfacesfromtheirsuperclass.

• Howevereachsubclass is a separateentitiy , eachmightrequire a differentresponsetosamemessage !!

Polymorphismsupportsdifferentresponses

Polymorphism : Example

publicabstractclassShape{

privatedoublearea;

publicabstractdoublegetArea();}

publicclassCircleextendsShape{

publicCircle(double r)

publicdoublegetArea()

return (area) ;}

}

• Objectsareoftenbuiltorcomposedfromotherobjects COMPOSITION

• Findout HAS-A relationships !!

• A computercontains video cards, drives, keyboards

 A computer has (a) video card(s)

 A computer has (a) drive(s)

• Encapsulation

• A single object contains both its data and behaviors and can hide what it wants from other objects.

• Inheritance

• A class can inherit from another class and take advantage of the attributes and methods defined by the super class

• Polymorphism:

• Similar objects may respond to the same emssage in different ways

• Composition:

• An object may be built from other objects