Introduction to object oriented concepts
This presentation is the property of its rightful owner.
Sponsored Links
1 / 34

Introduction to Object Oriented Concepts PowerPoint PPT Presentation


  • 100 Views
  • Uploaded on
  • Presentation posted in: General

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)

Download Presentation

Introduction to Object Oriented Concepts

An Image/Link below is provided (as is) to download presentation

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


Introduction to object oriented concepts

IntroductiontoObjectOrientedConcepts

WEEK1

Asst. Prof. Dr. Senem Kumova Metin


Classification of high level programming languages

Classification of HighlevelProgramminglanguages

  • Programmingparadigm : Alternativeapproachestotheprogrammingprocess

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

    • Functional(Lisp, ML)

    • Declarative(Logic) (Prolog,GPSS)

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


History of programming languages

History of Programming Languages


Programming languages 1 2

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)


Programming languages 2 2

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


What exactly is an object

Whatexactly is an object?

  • An OBJECT is an identitywhichincludesbothAttributes and Behaviors

    EXAMPLE -- > PERSON OBJECT

    Attributes : EyeColor, Age, Height …

    Behaviors : Walking, Talking, Breathing …


The object model

TheObject Model

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

  • Objects have state and processing ability

  • Objectsexchangemessages


Class and object

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.


Object oriented programming

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.


Procedural versus oo programming

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 !!


Procedural versus oo programming1

ProceduralVersus OO Programming

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

  • Procedural programming -> Top Down Design.

    • Start with a problem (procedure)

    • 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


Procedural versus oo programming2

ProceduralVersus OO Programming

  • InproceduralLanguages data

    is separatedfromprocedures

     The problem of data hiding !!

  • Global Data  nonproperdesign


Procedural versus oo programming example

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


What exactly is an object1

Whatexactly is an Object?

  • Attributes = Data

  • Theattributescontaintheinformationthatdifferentiatesbetweenthevariousobjects !!


What exactly is an object2

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


Object behaviors example

ObjectBehaviors: Example


Employee and payroll uml class diagrams

Employeeandpayroll UML classdiagrams


What exactly is a class

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 person class

Example: A Definition of a Personclass


Uml class diagram of person class

UML classdiagram of Personclass


Encapsulation

Encapsulation

  • 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 !!!


Encapsulation1

Encapsulation

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

  • Whatarethebenefits??

    • Reducesconceptualload

      • 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

  • Data Hiding is a majorpart of encapsulation.

  • Ingood OO design, an objectsholdonlyrevealtheinterfacesthatotherobjectsmusthavetointeractwith it !!!

  • Interface : Thecollection of publicbehaviorsthatprovidethecommunicationwiththeobject

  • Private data supports data hiding !!


A real world example of interface and implementation

A realworldexample of InterfaceandImplementation

  • RequestingObject : Toaster (requireselectricity)

  • Interface : Electricaloutlet

  • Implementation:Coalpoweredplantornuclearpowerplantor a localgenerator


A model of the interface implementation paradigm

A model of theInterface/ImplementationParadigm


Inheritance

Inheritance

  • 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

Inheritance : Classification of Vertebrates

  • Arrowsrepresent “is-a” relationship


Inheritance a simple example

Inheritance: A SimpleExample


Abstract classes

AbstractClasses


Polymorphism

Polymorphism

  • 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


Polymorphism1

Polymorphism

  • Polymorphism is tightlycoupledtoinheritance

  • Ininheritancehierarchy, allsubclassesinherittheinterfacesfromtheirsuperclass.

  • Howevereachsubclass is a separateentitiy , eachmightrequire a differentresponsetosamemessage !!

    Polymorphismsupportsdifferentresponses


Polymorphism example

Polymorphism : Example

publicabstractclassShape{

privatedoublearea;

publicabstractdoublegetArea();}

publicclassCircleextendsShape{

doubleradius;

publicCircle(double r)

{ radius=r;}

publicdoublegetArea()

{ area=3.14*radius*radius;

return (area) ;}

}


Composition

Composition

  • 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)


Conclusion

Conclusion

  • 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


  • Login