1 / 20

Object Oriented Programming

This course covers the basic principles of object-oriented programming, including abstraction, encapsulation, and information hiding. It also discusses concepts such as message passing, overloading, inheritance, overriding, polymorphism, and dynamic binding.

adonis
Download Presentation

Object Oriented Programming

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. Object Oriented Programming Basic Principles

  2. Abstraction Encapsulation Information Hiding Message Passing Overloading Inheritance Overriding Polymorphism Dynamic Binding Object Oriented Basic Principles • Abstraction, Encapsulation, Information hiding, Message passing and Overloading are covered in this course. • Inheritance, Polymorphism, Overriding and Dynamic binding are discussed in CSC 113. Dr. S. GANNOUNI & Dr. A. TOUIR

  3. Data Abstraction In order to process something from the real world we have to extract the essential characteristics of that object. Data abstraction is the process of: Refining away the unimportant details of an object, Keeping only the useful characteristics that define the object. For example, depending on how a car is viewed (e.g. in terms of something to be registered, or alternatively something to be repaired, etc.) different sets of characteristics will emerge as being important. Functionality Abstraction Modeling functionality suffers from unnecessary functionality may be extracted, or alternatively, an important piece of functionality may be omitted. Functionality abstraction is the process of determining which functionality is important. view view view Abstraction Principle Dr. S. GANNOUNI & Dr. A. TOUIR

  4. Abstraction Principle • Choose only attributes and methods relevant to your application • A Person can have attributes : name, age, length, weight • For a banking application, length and weight has nothing to do • So you should ignore these…. • Choose only what is relevant and needed for application

  5. Encapsulation Principle • Abstraction involves reducing a real world entity to its abstraction essential defining characteristics. • Encapsulation extends this idea by also modeling and linking each data of an entity to the appropriate functionality of that entity. Dr. S. GANNOUNI & Dr. A. TOUIR

  6. Encapsulation Principle A concept of ‘Self-containing’ An object is like a black box. The internal details are hidden. Encapsulation is the practice of including in an object everything it needs hidden from other objects. The internal state is usually not accessible by other objects.

  7. Encapsulation Gives Classes • OOP makes use of encapsulation to ensure that data is used in an appropriate manner. • by preventing from accessing data in a non-intended manner (e.g. asking if an Integer is true or false, etc.). • Through encapsulation, only a predetermined appropriate group of operations may be applied (have access) to the data. • Place data and the operations that act on that data in the same class. • Encapsulation is the OO principle that allows objects to contain the appropriateoperations that could be appliedon the data they store. • My Nokia-N71 cell-phone stores: • My contacts, • Missed calls • … etc. • My Nokia-N71 may perform the following operations on the data it contains: • Edit/Update/Delete an existing contact • Add a new contact • Display my missed calls. • …etc. Dr. S. GANNOUNI & Dr. A. TOUIR

  8. Information Hiding Principle • Information hiding - ‘internal’ structure is hidden from their surroundings • Behaviors (methods) and information (attributes) are represented or implemented internally • Functionality and behavior characterized by ‘interfacing’ operations • This is achieved by the use of classes and the access modifiers

  9. Information Hiding Principle • Limit access to data only to internal operations that need it. • OO classes hide the data as private data members and use public accessor operations to get at it. • The scope of the data is limited to the class. • Information hiding protects: • data items (attributes). • the internal structure of a class. • implementation details of a class.

  10. Access Modifiers • Access modifiers aid to achieve the encapsulation and information hiding principle by preventing unauthorized or accidental access to attributes and methods. Through which you can control how the methods and attributes can be accessed: • public class Person • { • private string name; • private int age; • public void Work() • { • } • }

  11. Access Modifiers (cont.) Accessibilities options • public – Accessible to all • private – Accessible to containing class • protected – Accessible to containing or derived classes (will be described in CSC113) • In most cases: fields are private or protected, and methods are public.

  12. Message Passing PrincipleOR Method Invocation • Information hiding prevent the data inside the object from being directly accessed by outsiders. • Encapsulation allows objects to include the appropriate operations that could be applied on the data stored in the object. • So, the data that an object stores would be accessed only through appropriate operations (methods).

  13. Message Passing PrincipleOR Method Invocation • Message passing is the principle that allows objects to communicate by exchanging messages. • Passing a message to an object means ordering this object to execute a specific method. • This is also called method invocation

  14. Message Passing PrincipleOR Method Invocation • Objects communicate through messages (invoking or calling methods of other objects) • Methods: mostly public • Fields: Private or protected • You send messages to an object by making method calls. • However, we need to create objects (instances) from classes first

  15. Method Invocation • Invoking a method of a given object requires using: • the instance variable that refers to this object. • the dot (.) operator as following: instanceVariable.methodName(arguments) public class CourseRegistration { public static void main(String[] args) { Course course1, course2; //Create and assign values to course1 course1= new Course( ); course1.enterDataFromKeyBoard(); course1.display(); //Create and assign values to course2 course2 = new Course( ); course2.enterDataFromKeyBoard(); course2.display(); } }

  16. UML Representation for Object Oriented systems • UML (Unified Modeling Language) is a graphical representation scheme used for modeling object oriented systems • An OO system is designed using this language in a form of diagrams, with one standard set of graphical notations Dr. S. GANNOUNI & Dr. A. TOUIR

  17. What is a Class Diagram? • A class diagram is a graphical representation that describes the types of objects in the system and the various kinds of relationships that exist among them. • A central modeling technique that runs through nearly all object-oriented methods. • The richest notation in UML.

  18. ClassName • att1: dataType1 • … • atti: dataTypei Attributes Methods (Services) + m1(…): dataType1 + ... + mj(…): dataTypej UML Representation of a Class • UML represents a class with a rectangle having 3 compartments stacked vertically. • The top compartment shows the class's name. • The middle compartment lists the attributes. • The bottom compartment lists the operations: methods or services. Dr. S. GANNOUNI & Dr. A. TOUIR

  19. Student - name: string- age: int +AttendLect):void+Study():void Essential Elements of a UML Class Diagram • Class name (top) • Attributes/ fields (middle) • Methods (bottom) • Links between different classes define relationships (will be covered in CSC113) Class Name Attributes Methods

  20. ClassName • att1: dataType1 • … • atti: dataTypei Attributes Methods (Services) + m1(…): dataType1 + ... + mj(…): dataTypej UML Representation of a Class(UML Class Diagram) • UML uses three symbols to represent the visibility of the class’ members. • + : mentions that the member is public. • - : mentions that the member is private. • # : introduced in the CSC 113.

More Related