Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Paradigm Programming Paradigms En Mohd Norafizal A.Aziz.

Similar presentations


Presentation on theme: "Object Oriented Paradigm Programming Paradigms En Mohd Norafizal A.Aziz."— Presentation transcript:

1 Object Oriented Paradigm Programming Paradigms En Mohd Norafizal A.Aziz

2 Contents Definition of object oriented Definition of object oriented Basic concepts Basic concepts Objects Objects Classes Classes Messages Messages Encapsulation Encapsulation Inheritances Inheritances Abstract classes and Interfaces Abstract classes and Interfaces Polymorphism Polymorphism Sample of code Sample of code Conclusion Conclusion

3 Blind man and Elephant

4 What is Object Oriented Allows programmers to write computer programs by representing elements of a real-world problem in the form of so-called objects. Allows programmers to write computer programs by representing elements of a real-world problem in the form of so-called objects. Objects are represent both: behaviors of real world objects as well as their characteristics. Objects are represent both: behaviors of real world objects as well as their characteristics. All work in this concepts are using messages. All work in this concepts are using messages.

5 Advantages of Object Oriented OOP provides a clear modular structure for programs. OOP provides a clear modular structure for programs. OOP is easy to maintain. OOP is easy to maintain. OOP provides a good framework for code libraries. OOP provides a good framework for code libraries.

6 Objects Objects are the physical and conceptual things we find in the universe around us. Objects are the physical and conceptual things we find in the universe around us. Hardware, software, documents, human beings, and even concepts are all examples of objects. Hardware, software, documents, human beings, and even concepts are all examples of objects. Objects are thought of as having state. The state of an object is the condition of the object, or a set of circumstances describing the object. Objects are thought of as having state. The state of an object is the condition of the object, or a set of circumstances describing the object. However, it is possible for some objects to change their own state. If an object is capable of spontaneously changing its own state, we refer to it as an “object with life”. However, it is possible for some objects to change their own state. If an object is capable of spontaneously changing its own state, we refer to it as an “object with life”.

7

8 Objects is … An objects has a state, exhibits some well defined behavior and has a unique identity.

9 Generally, OOP approach may be seen as manipulation with multiple objects. Generally, OOP approach may be seen as manipulation with multiple objects. Programmers can : Programmers can : Create new objects Create new objects Send message to existing objects Send message to existing objects Collect responses in a form of objects to which other messages may be sent. Collect responses in a form of objects to which other messages may be sent.

10 Sample of coding BankAccount myAccount = new BankAccount (); String myname = new String (‘Fizal’); Employee meAsemployee = new Employee (myname, myAccount); Consists of three fundamentals part : Variable declaration – Instantiation -- Initialization

11 Classes A class represent a set of objects that share common structure and a common behavior. A class represent a set of objects that share common structure and a common behavior. Example: CAR Example: CAR State ( gear, speed, etc) State ( gear, speed, etc) Behavior (change gear, accelerate etc) Behavior (change gear, accelerate etc)

12 Classes is … Is a prototype that defines variables and methods that are common to all objects of the same kind.

13 Sample of coding Public class Employee { // variables private String Name; private BankAccount B_Account; // methods // methods public String salary (int sum) { // method body }}

14 Public class Name { private String nama; public Name () // default constructor {} public Name (String nama) {this.nama = nama; } String getNama() {return nama; } void setNama(String Nama) {this.nama = nama;} public String toString() {return nama } }

15 class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println("cadence:"+cadence+" speed:"+speed+" gear:"+gear); } }

16 Import java.io; Public class hello { public static void main (String args []) {System.out.pritnln(“Hello…World”);}}

17 Messages Single objects are not very useful. Instead, an object usually appears as just one object of an object-oriented program that contains many objects. Single objects are not very useful. Instead, an object usually appears as just one object of an object-oriented program that contains many objects. In such program all works is done by interaction between these objects. In such program all works is done by interaction between these objects.

18 Sample of messages Employee meAsemployee = new Employee(myname, myAccount); meAsemployee.salary(1000);

19 References Java Tutorials: http://java.sun.com/docs/books/tutorial/java/concepts/ Java Tutorials: http://java.sun.com/docs/books/tutorial/java/concepts/ http://java.sun.com/docs/books/tutorial/java/concepts/ Wikipedia: Wikipedia: http://en.wikipedia.org/wiki/Object-oriented_programming Keywords: Keywords: object oriented concepts in java with examples. object oriented concepts in java with examples. Object Oriented concepts Object Oriented concepts


Download ppt "Object Oriented Paradigm Programming Paradigms En Mohd Norafizal A.Aziz."

Similar presentations


Ads by Google