250 likes | 433 Vues
F3031 Object Oriented Programming. CHAPTER 1 INTRODUCTION TO OBJECT ORIENTED PROGRAMMING (OOP). By: PN. NOR ANISAH BINTI MOHD SAAD. CHAPTER 1.0 : INTRODUCTION TO OOP. 1. Define OOP History of OOP Advantages of using OOP Basic Terminologies of OOP
E N D
F3031 Object Oriented Programming CHAPTER 1 INTRODUCTION TO OBJECT ORIENTED PROGRAMMING(OOP) By: PN. NOR ANISAH BINTI MOHD SAAD
CHAPTER 1.0 : INTRODUCTION TO OOP 1 Define OOP History of OOP Advantages of using OOP Basic Terminologies of OOP Abstraction and Encapsulation Structured and OOP Approach 2 3 4 5 6
Define OBJECT 1 • An object can be considered as a "thing" that can perform a set of activities (behaviours). • For example, a "Student" object can tell you its name or its address.
Define OBJECT • An object is a "black box" which receives and sends messages. • A black box actually contains codeand data • Messages define the interface to the object. • Everything an object can do is represented by its message interface. • So you shouldn't have to know anything about what is in the black box in order to use it.
Define OBJECT ORIENTED PROGRAMMING 1 • In object-oriented programming, objects interact with each other by messages (specific codes). • The only thing that an object knows about another object is the object's interface. Each object's data and method is hidden from other objects. • In other words, the interface encapsulates the object's code and data.
Define OOP 1 • A type of programming where the programmer can define data types and types of operation (function), which will be performed on the data structure. Matric No. Marks Integer Float Sorting students Calculate marks
Define OOP (cont.) 1 • Object-oriented programming is a method used to write programs where data and behaviours are packaged together in one class. Object is a member of a class. • Object Oriented Programming is programming which is oriented around objects, thus taking advantage of Encapsulation, Polymorphism, and Inheritance to increase code reuse and decrease code maintenance.
Define OOP (cont.) 1 • A language or technique is object-orientedif it directly supports: • Abstraction- providing some form of classes and objects. • Inheritance - providing the ability to build new abstractions out of existing ones. • Runtime polymorphism - providing some form of runtime binding.
HISTORY of oop 2 • Early 1960s • SIMULA was the first object language. • developed by Kristen Nygaard and Ole-Johan Dahl in Norway. • It was designed for the purpose of creating simulations (ships) Kristen Nygaard Ole-Johan Dahl
HISTORY of oop 2 • 1970s • Alan Kay – idea to integrated the SIMULA into personal computer • Joint venture with Xerox Parc – created the first personal computer called Dynabook • Smalltalk was the object-oriented language developed for programming the Dynabook • It was a simulation and graphics-oriented programming language. Alan Kay
HISTORY of oop 2 • 1980s • Bjorn Stroustrup integrated object-oriented programming into the C language • The resulting language was called C++ and it became the first object-oriented language to be widely used commercially Bjorn Stroustrup
HISTORY of oop 2 • 1990s • a group at Sun led by James Gosling developed a simpler version of C++ called Java • Java programming meant to be a programming language for video-on-demand applications • No +ve response - re-oriented its focus and marketed Java as a language for programming Internet applications • The language has gained widespread popularity as the Internet has boomed James Gosling
Advantages of using oop 3 • Code extensibility • Ability to add codes, which are already existing and consistent with needs. • Code reusability • Existing code can be tested first before it is inherited from previous module. • This will save cost and time needed to develop software. • With this method, it will help to increase programmer’s productivity. • Represent real world • Using object-oriented concept, it will assist the programmer in creating a module because data used represents real situations. • Data security • The use of encapsulation concept has made data to be protected from misuse by an unauthorized person.
Basic terminologies of OOP 4 1 Object Class Encapsulation Data Abstraction Inheritance Polymorphism 2 3 4 5 6
Basic terminologies of OOP (cont.) 4 1 Object • Object is the term used to explain many things. • Example: student, chair and circle. • An Object consists of data and method. • Properties of an object are called data. • In the real world, characteristics of an object can be • divided into two types: • Data that can be seen such as a human with two hands. • Data that cannot be seen such as a human with a name. • Method is a set of function that manipulates data, • such as method DetermineStatus() can determine • exam result for object student.
Basic terminologies of OOP (cont.) 4 2 Class • A set of objects that have similar attributes (data) and methods. • Attributes and methods of a class can be used by each object • from that class. class Student { String name, address, status; inticno, sid; double marks; char DetermineStatus() { if marks >= 40 status = “Pass”; else status = “Fail”; } } data method Class
Basic terminologies of OOP (cont.) 4 3 Encapsulation • Encapsulation is a process of tying together all data and • methods that form a class and control the access to data by • hiding its information. • It enables access to object just by using methods of that object. • It is one of the security features in OOP. • Attributes and methods of a class can be used by each object • from that class. Class Student Name, Student ID, Address, IC No Calculate_result() Determine_grade() Print_result()
Class Box Characteristics Behaviors Data abstraction Length, width, depth length Object Box depth width Calculate_Volume() Calculate_Area() Figure 1.2: Describe data abstraction concept in OOP for object Box. Basic terminologies of OOP (cont.) 4 4 Data Abstraction • Data abstraction is a process to delete all unnecessary • attributes and remain the necessary attributes to describe an • object • Attributes and methods of a class can be used by each object • from that class.
Class A Base class for B Derived class from class A Base class for class C, D and E Class B Class C Class D Class E Derived class from class B Basic terminologies of OOP (cont.) 4 5 Inheritance • Create a new class from an existing class together with new • attributes and behaviours. • The new class will have the same ability as the base class. • Use the concept of code reusability.
Basic terminologies of OOP (cont.) 4 6 Polymorphism • Polymorphism is a process of giving the same message to • two or more different objects and produce different behaviours • depending on how the objects receive the message. • It is said to be “One interface, many methods”. Contoh: Method: Keluarkanwangandadari bank: Objek: Pelajar 1 : Menggunakanmesin ATM yang disediakanolehpihak bank dimanaakaundibuka Pelajar 2 : Menggunakanmesin ATM (MEPS) dari bank lain