Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.

Similar presentations


Presentation on theme: "Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3."— Presentation transcript:

1 Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3

2 Slide - 2 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Object-Oriented Programming: A New Programming Paradigm…  What is Matlab's programming paradigm?  Matlab is procedural: the focus is on the functions (procedures)  What is the programming paradigm in OOP?  As the name suggests, in OOP the focus is on  OBJECTS  This doesn't say much unless we understand what we mean with the term Object… So let's move on.

3 Slide - 3 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Objects Combine Properties & Behavior [1/2]  Remember following Structures:  person.firstname = 'John';  person.lastname = 'Leonard';  person.address1 = '803 Shallowford Lane';  person.city = 'Peachtree City';  person.state = 'GA';  person.zip = '30269-4289';  A structure contains data in an organized fashion.

4 Slide - 4 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Objects Combine Properties & Behavior [2/2]  If we add functions or methods to a structure, it becomes an object:  person.print_address();  person.set_lastName('Paredis');

5 Slide - 5 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng More Examples of Objects [1/2]  Car:  Properties: color, speed, fuel consumption, HP…  Behaviors: start, stop, turning, …  Triangle:  Properties: area, perimeter, linestyle, location,…  Behaviors: translate, rotate, shrink, flip,…  Date:  Properties: year, month, day, …  Behaviors: setDate, getMonth, isGreater, …

6 Slide - 6 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng More Examples of Objects [1/2]  Properties: information about the object  Behaviors: methods to set, get and process properties  Combining properties and behaviors in objects is called  Encapsulation

7 Slide - 7 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Objects Combine Properties and Behavior: So What? Why should we care? [1/2]  Black Box Philosophy:  Objects perform computation by making requests of each other through the passing of messages  The only way to interact with an object is through its methods! http://java.sun.com/docs/books/tutorial/java/concepts/object.html http://catalog.com/softinfo/objects.html Messages Code Data

8 Slide - 8 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Objects Combine Properties and Behavior: So What? Why should we care? [2/2]  This is called Information Hiding  (the data is hidden from the user)  The collection of all methods is called the interface of the object http://java.sun.com/docs/books/tutorial/java/concepts/object.html http://catalog.com/softinfo/objects.html

9 Slide - 9 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Encapsulation and Data Hiding [1/2]  Properties (Variables)  Speed  RPM  Current Gear  Methods (Functions)  Braking  Acceleration  Turn  Changing Gears

10 Slide - 10 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Encapsulation and Data Hiding [2/2]  These methods are independent of how the bicycle has been built (hides the implementation)  You can control access to members of an object

11 Slide - 11 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Working with Objects: Messages [1/2]  Objects perform computation by making requests of each other through the passing of messages  Parts of a message –  The object to which the message is addressed  The name of the method to perform  Any parameters needed by the method\

12 Slide - 12 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Working with Objects: Messages [2/2]  Different objects may respond differently to an identical message:  bicycle.changeGears(lowerGear)  car.changeGears(lowerGear)  The same name and the same argument, but a different method = POLYMORPHISM  A method is defined only in the scope of a particular type of object, called class  Polymorphism is also called: function overloading

13 Slide - 13 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Class and Object [1/2]  Now that we know what an object is all about, let's look at how we can organize these objects  Class = A blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind Objects are individual instances of a class

14 Slide - 14 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Class and Object [2/2]  House Plans:  the architectural drawings that describe how a house is to be constructed  A House:  The house built from the plans is an instance of the House Class. The process of building the house is called Instantiation

15 Slide - 15 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Organizing Objects: Inheritance [1/2] Super class (parent) Sub class (child) Children inherit properties behaviors

16 Slide - 16 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Organizing Objects: Inheritance [2/2]  Sub class (Child) A class that is derived from a particular class, perhaps with one or more classes in between  Super class (Parent) A class from which a particular class is derived, perhaps with one or more classes in between  Inheritance promotes  Reuse of code  Better Management of code

17 Slide - 17 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Abstraction in OOP [1/2]  Abstractions reveal causes and effects, expose patterns and frameworks and separate what's important from what's not  Abstraction in programming helps you make your ideas concrete in your code without obscuring the architecture with details  In procedural languages:  structures and functions are abstractions

18 Slide - 18 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Abstraction in OOP [2/2] OOP takes abstraction one step further through:  encapsulation  data hiding  polymorphism  Inheritance

19 Slide - 19 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Object-Oriented Programming [1/2]  A Quick Review:  “OOP is more a way of thinking than just a programming technique” – “conceptual tool that you use in thinking how to solve a problem”  Computer objects form the basis  Objects treated as real life objects  Identities  Properties  Behaviors  Data and functionality encapsulated in an object  Data hidden behind methods

20 Slide - 20 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Object-Oriented Programming [2/2]  Objects organized in class hierarchies: inheritance  Objects interact through messages – methods  Polymorphism: the same message has a different meaning for different objects

21 Slide - 21 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Benefits of Object Oriented Programming  Analysis and Design made easier  Understanding of code made easier  Code Reuse  Ease of maintenance and enhancement  Simplifies collaboration  Fewer and shorter design iterations

22 Slide - 22 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Examples of Programming Languages  Procedural languages  C  FORTRAN  BASIC  Pascal  Object Oriented languages  C++  Smalltalk  Java

23 Slide - 23 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Assignment#2a: OOP vs Procedural Programming  Object-Oriented      Procedural     Due date: Friday, February 27 th, 2004

24 Slide - 24 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Assignment#2b: Object Oriented Philosophy  “Simulate the functionality of your computer using the object oriented philosophy”  Draw a diagram of the components present in the computer. What is the flow of information between these components? Leverage from previous lectures.  Identify the classes and objects that you would need to simulate these components. How do these classes interact?  Identify the variables and methods that you would assign to each class. Due Date: Friday, March 5 th, 2004

25 Slide - 25 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng References and Additional Reading  “Object Oriented Programming, ” http://www.toodarkpark.net/computers/objc/oop.h tml  “Core Java, ” Cay S. Horstmann and Gary Cornell, Sun Microsystems  “ Thinking in C++, ” Bruce Eckel, http://www.mindview.net/Books/TICPP/ThinkingInC PP2e.html  “ Introduction to Object Oriented Programming, ” Timothy Budd, ftp://ftp.cs.orst.edu/pub/budd/oopintro/3rdEdition /info.html

26 Slide - 26 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng Closure  Learning  Object oriented programming is more a philosophy than mere technique to develop programs…  This philosophy provides modularity to programs  Modularity provides openness to change…  Enables developing complex systems  Food for Thought  How will object oriented philosophy help in the future of software development?  How can the object oriented philosophy based on modularity be used in your field of specialization?  What changes are required to adapt this philosophy to your field?

27 Slide - 27 OOP Lecture 2004 Dr. –Ing. Ir. Kalamullah Ramli, M.Eng The End QUESTIONS & COMMENTS ?


Download ppt "Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3."

Similar presentations


Ads by Google