Download presentation
Presentation is loading. Please wait.
Published byMelina Bailey Modified over 8 years ago
1
Introduction To OOP 1.0 Fundamentals Of Java Programming Language 2.0 Exception Handling 3.0 Classes, Inheritance And Polymorphism 4.0 1 © 2011 | PN AZRINA BINTI TAHIR
2
2
3
Define OOP 1 Describe the History Of OOP 2 List the Advantages Of Using OOP 3 Illustrate the Basic Terminologies Of OOP 4 Distinguish between Abstraction & Encapsulation 5 Differentiate between Structured Programming & OOP Approach 6 3 © 2011 | PN AZRINA BINTI TAHIR
4
According to Wikipedia, Object Oriented Programming (OOP) is a programming technique that uses “objects” to design the applications and computer programs. It also can be define as a type of programming where the programmer can define data types and types of operations, which will be performed on the data structure. Example: Datadata types Data Structure Student No. Integer Mark float Types of operation: Student No. : Sort student list based on Student No. Mark : Calculate mark. © 2011 | PN AZRINA BINTI TAHIR 4
5
By using this method, data structure will become an object such as Student object, which consists of data and functions. The programmer can create relationship between one object with another object such as an object inherits characteristics from another object 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. © 2011 | PN AZRINA BINTI TAHIR 5
6
In the 1960s, Simula language were developed by Norwegian Computing Center. ▫ It became the first OOP language which applies the OOP concepts. ▫ It was designed for the purpose of creating simulations, and was developed by Kristen Nygaard and Ole-Johan Dahl in Norway. In the 1970s, Alan Kay developed Smalltalk language at Xerox Parc (Palo Alto Research Center). ▫ Targeted to be understandable to people with no prior training in computer use. ▫ Demonstrated by experiments conducted using children as programmers In the 1980s, Bjarne Stroustrup at Bell Lab who had learned Simula during his PHD studies develop C++ as an extension of C. Later many other OOP languages were developed: Eiffel, Objective-C, Actor,Object Pascal and etc. © 2011 | PN AZRINA BINTI TAHIR 6
7
Code extensibility / kod boleh ditambah Ability to add codes, which are already existing and consistent with needs. Code reusability / kod boleh diguna berulangkali 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. © 2011 | PN AZRINA BINTI TAHIR 7
8
Represent real world / menggambarkan dunia sebenar Using object-oriented concept, it will assist the programmer in creating a module because data used represents real situations. Data security / keselamatan data The use of encapsulation concept has made data to be protected from misuse by an unauthorized person. © 2011 | PN AZRINA BINTI TAHIR 8
9
9 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. Object : Student Data : name, address, icno, sid, marks, status Method : DetermineStatus()
10
© 2011 | PN AZRINA BINTI TAHIR 10 2.Class A set of objects that have similar attributes( characteristics, which can be seen. ) and methods. Attributes and methods of a class can be used by each object from that class. class Student { String name, address, status; int icno, sid; double marks; char DetermineStatus() { if marks >= 40 status = “Pass”; else status = “Fail”; } Class Example 1 : Definition of Class Student data method Example 2 : Definition of Class Box class Box { double width, height, depth; double ComputeVolume() { return( width * height * depth ); } double ComputeArea() { return( width * height ); } } data method Class
11
© 2011 | PN AZRINA BINTI TAHIR 11 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 object-oriented programming (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() Figure above Explains the concept of encapsulation in OOP for class Student Based from the example given, data and methods are combined in one class. If the college management wants to get the status whether a student “pass” or “fail”, they only have to know the status without knowing how to determine or calculate the grade. So, this is a way of implementing encapsulation where the code in the program is hidden thus to prevent from being modified.
12
© 2011 | PN AZRINA BINTI TAHIR 12 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. Student Object Abstraction Name, Student ID, Address, IC No Attribute Calculate_mark (), Determine_grsde (), Print_result () Behaviors Student Class Figure Explain about abstraction concept
13
© 2011 | PN AZRINA BINTI TAHIR 13 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. Class A Class B Class C Base class to class B Derived class to class A Base class to C, D and E Derived class to class B Class E Class D Figure : Relationship between one class with another class. Derived class can be inherits characteristic from a base class.
14
© 2011 | PN AZRINA BINTI TAHIR 14 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”. Example 1: Message: Withdraw a money from bank Action Object Student1 : Using ATM machine from Bank account. Student2 : Using ATM Machine from other Bank (MEPS)
15
AbstractionEncapsulation Delete all unnecessary data and remain the necessary data only control the access to data by hiding its information © 2011 | PN AZRINA BINTI TAHIR 15
16
© 2011 | PN AZRINA BINTI TAHIR 16
17
© 2011 | PN AZRINA BINTI TAHIR 17
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.