1 / 27

Object Oriented Programming Principles

Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia. Session-3. Object Oriented Programming Principles. Object-Oriented Programming: A New Programming Paradigm…. What is Matlab's programming paradigm?

cade-foley
Download Presentation

Object Oriented Programming Principles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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. 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. 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. 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. 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. Messages Code Data 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

  8. 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. Encapsulation and Data Hiding [1/2] • Properties (Variables) • Speed • RPM • Current Gear • Methods (Functions) • Braking • Acceleration • Turn • Changing Gears

  10. 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. 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. 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. 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. 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 Class and Object [2/2]

  15. Super class(parent) Sub class(child) Organizing Objects: Inheritance [1/2] • Children inherit • properties • behaviors

  16. 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. 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. Abstraction in OOP [2/2] OOP takes abstraction one step further through: • encapsulation • data hiding • polymorphism • Inheritance

  19. 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 Abstraction

  20. 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. 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 Abstraction

  22. Examples of Programming Languages • Procedural languages • C • FORTRAN • BASIC • Pascal • Object Oriented languages • C++ • Smalltalk • Java

  23. Object-Oriented Procedural Assignment#2a: OOP vs Procedural Programming Due date: Friday, February 27th, 2004

  24. 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 5th, 2004

  25. References and Additional Reading • “Object Oriented Programming, ” http://www.toodarkpark.net/computers/objc/oop.html • “Core Java, ” Cay S. Horstmann and Gary Cornell, Sun Microsystems • “Thinking in C++, ” Bruce Eckel, http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html • “ Introduction to Object Oriented Programming, ” Timothy Budd, ftp://ftp.cs.orst.edu/pub/budd/oopintro/3rdEdition/info.html

  26. 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. The End QUESTIONS & COMMENTS ?

More Related