1 / 34

Introduction to Object Oriented Concepts

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)

cybele
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IntroductiontoObjectOrientedConcepts WEEK1 Asst. Prof. Dr. Senem Kumova Metin

  2. 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)

  3. History of Programming Languages

  4. 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)

  5. 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

  6. Whatexactly is an object? • An OBJECT is an identitywhichincludesbothAttributes and Behaviors EXAMPLE -- > PERSON OBJECT Attributes : EyeColor, Age, Height … Behaviors : Walking, Talking, Breathing …

  7. TheObject Model • A OO-software system is a set of cooperating objects • Objects have state and processing ability • Objectsexchangemessages

  8. 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.

  9. 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.

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

  11. 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

  12. ProceduralVersus OO Programming • InproceduralLanguages data is separatedfromprocedures  The problem of data hiding !! • Global Data  nonproperdesign

  13. 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

  14. Whatexactly is an Object? • Attributes = Data • Theattributescontaintheinformationthatdifferentiatesbetweenthevariousobjects !!

  15. 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

  16. ObjectBehaviors: Example

  17. Employeeandpayroll UML classdiagrams

  18. 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

  19. Example: A Definition of a Personclass

  20. UML classdiagram of Personclass

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

  22. 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

  23. Data Hiding • Data Hiding is a majorpart of encapsulation. • Ingood OO design, an objectsholdonlyrevealtheinterfacesthatotherobjectsmusthavetointeractwith it !!! • Interface : Thecollection of publicbehaviorsthatprovidethecommunicationwiththeobject • Private data supports data hiding !!

  24. A realworldexample of InterfaceandImplementation • RequestingObject : Toaster (requireselectricity) • Interface : Electricaloutlet • Implementation:Coalpoweredplantornuclearpowerplantor a localgenerator

  25. A model of theInterface/ImplementationParadigm

  26. 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)

  27. Inheritance : Classification of Vertebrates • Arrowsrepresent “is-a” relationship

  28. Inheritance: A SimpleExample

  29. AbstractClasses

  30. 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

  31. Polymorphism • Polymorphism is tightlycoupledtoinheritance • Ininheritancehierarchy, allsubclassesinherittheinterfacesfromtheirsuperclass. • Howevereachsubclass is a separateentitiy , eachmightrequire a differentresponsetosamemessage !! Polymorphismsupportsdifferentresponses

  32. Polymorphism : Example publicabstractclassShape{ privatedoublearea; publicabstractdoublegetArea();} publicclassCircleextendsShape{ doubleradius; publicCircle(double r) { radius=r;} publicdoublegetArea() { area=3.14*radius*radius; return (area) ;} }

  33. 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)

  34. 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

More Related