Object Oriented Programming Procedural Languages Early highlevel languages
Object Oriented Programming
Procedural Languages • Early high-level languages are typically called procedural languages. • Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure. • Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript
Object-Oriented Languages • Most object-oriented languages are high-level languages. • The focus of OOP languages is not on structure, but on modeling data. • Programmers code using “blueprints” of data models called classes. • Examples of OOP languages include C++, Java etc.
Object Oriented Programming 1. Object • An object contains both data and methods that manipulate that data. – The data represent the state of the object – Data can also describe the relationships between this object to object. Example - You could create an object representing a rabbit • It would have data: – Color – breed – size • And methods (behavior): – eat, hide, run etc.
Object Oriented Programming 2. Classes • A class is a blueprint from which individual objects are created. • 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
Object Oriented Programming Example class dog { String breed; int age; String color; Void barking() {} Void hungry() {} }
Object Oriented Programming Example- create sum class in java class sum { public static void main(String a[]) { int a, b; a=10, b=20; System. out. println(“Sum=“+a+b); } }
Generalization • Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized super class. Shared characteristics can be attributes, associations, or methods. • It is a bottom up approach.
Inheritance • Generalization is implemented in programming with the concept of inheritance. • Inheritance permits a subclass to share attributes and operations defined in the super class.
Inheritance
Aggregation • Aggregation is a relationship between two classes that is best described as a "has-a" and "whole/part" relationship. • Ownership occurs because there can be no cyclic references in an aggregation relationship. Example- There are two classes student and subject. Student has a subject java This statement defines the property of ownership.
When use Aggregation • Code reuse is also best achieved by aggregation when there is no is-a relationship. • Inheritance should be used only if the relationship is-a is maintained throughout the lifetime of the objects involved; otherwise, aggregation is the best choice.
Abstraction • Abstraction is a process to abstract or hide the functionality and provide users or other programmers to use it only. Like for the method System. out. println(). • Abstraction is implemented in Java using interface and abstract class. Example – sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery.
- Slides: 13