Presentation is loading. Please wait.

Presentation is loading. Please wait.

: Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1.

Similar presentations


Presentation on theme: ": Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1."— Presentation transcript:

1 : Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1

2   The 1960s gave birth to structured programming. This is the method encouraged by languages such as C and Pascal. The use of structured languages made it possible to write middling complex programs fairly easily. Structured languages are characterized by their support for stand-alone subroutines, local variables, rich control constructs, and their lack of reliance upon the GOTO. Although structured languages are a powerful tool, even they reach their limit when a project becomes too large. 2 Introduction to Object-Oriented Programming

3   Object oriented programming involves programming using objects. An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner. For example, a student, circle. 3 What Is Object-Oriented Programming?

4  4 Concept: Object have state and behaviors  The state of an object is represented by data fields with their current values.  The behavior of an object is defined by a set of methods. A class can be defined as a template that describes the behaviors that object of its type support.  Every object belongs to (is an instance of) a class  An object may have fields, or variables(The class describes those fields)  An object may have methods (The class describes those methods)

5  5 Objects Is a bank account an object? Is an account no. an object? Is a checking account an object?

6  6 Example of a class public class Student { String name; int age; void getname(){ } void setage(){ } } State of objectbehaviors of objectobject

7   To support the principles of object-oriented programming, all OOP languages have three features in common:  Encapsulation  Polymorphism  Inheritance. 7 Fundamental Principles of OOP

8   Encapsulation is used to hide the values or state of a structured data object inside a class. That is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. In an object-oriented language, code and data may be combined in such a way that a self-contained. When code and data are linked together in this fashion, an object is created. In other words, an object is the device that supports encapsulation. Within an object, code, data, or both may be private to that object or public. 8 Encapsulation

9  9 Encapsulation – Example PersonPerson -name : string -age : int -name : string -age : int +Person(string name, int age) +Name : string { get; set; } +Age : TimeSpan { get; set; } +Person(string name, int age) +Name : string { get; set; } +Age : TimeSpan { get; set; }

10   Object-oriented programming languages support polymorphism, which is characterized by the phrase "one interface, multiple methods." In simple terms, polymorphism is the attribute that allows one interface to control access to a general class of actions. 10 Polymorphism

11   For example: UndergraduateStudent and GraduateStudent are subclasses of Student 11 Count..

12   Inheritance is the process by which one object can get the properties of another object. This is important because it supports the concept of classification. If you think about it, most knowledge is made manageable by hierarchical classifications.  For example, a Red apple is part of the classification apple, which in turn is part of the fruit class, which is under the larger class food. 12 Inheritance

13   Inheritance let us to create a new class from the existing classes.  The new class is called subclass and the existing class is called superclass.  The subclass inherits the properties of the superclass.  The properties refer to the method or the attribute (data)  Inheritance is ‘is-a’ relation Example: if a Circle inherits the Shape class, hence the Circle is a Shape. (See the next figure) 13 Count..

14  14 Count..

15   Single inheritance  Is a subclass that derived from a single/one superclass (existing class)  Multiple inheritance  Is a subclass that derived from more than one superclass  Not supported by Java. 15 Count..

16 16 Single Multiple

17 17 Q?


Download ppt ": Maha Sabri Altememe Lecturer : Maha Sabri Altememe Lecture :1 1."

Similar presentations


Ads by Google