ject Oriented Programming Principl ject Oriented Programming Principl Lecturer: Lecturer: Kalamullah Ramli Kalamullah Ramli Electrical Engineering Dept. Electrical Engineering Dept. University of Indonesia University of Indonesia Session- Session- 3 3
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? - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Object-Oriented Object-Oriented Programming:Programming:A New Programming A New Programming Paradigm… Paradigm… What is Matlab's programming What is Matlab's programming
paradigm?paradigm? Matlab is Matlab is proceduralprocedural: the focus is on : the focus is on
the the functionsfunctions (procedures) (procedures) What is the programming paradigm What is the programming paradigm
in OOP?in OOP? As the name suggests, in OOP the As the name suggests, in OOP the
focus is onfocus is on OBJECTSOBJECTS
This doesn't say much unless we This doesn't say much unless we understand what we mean with the understand what we mean with the term term ObjectObject… So let's move on.… So let's move on.
Objects Combine Properties and Objects Combine Properties and Behavior:Behavior:So What? Why should we care? So What? Why should we care? [1/2][1/2]
Black Box PhilosophyBlack Box Philosophy:: Objects perform Objects perform
computation by making computation by making requests of each other requests of each other through the passing of through the passing of messagesmessages
The only way to interact The only way to interact with an object is through with an object is through its methods!its methods!
Encapsulation and Data Hiding Encapsulation and Data Hiding [2/2][2/2]
These methods are independent of These methods are independent of how the bicycle has been built how the bicycle has been built (hides the implementation)(hides the implementation)
You can control access to members You can control access to members of an objectof an object
Working with Objects: Working with Objects: Messages Messages [1/2][1/2]
Objects perform computation by Objects perform computation by making requests of each other through making requests of each other through the passing of messages the passing of messages
Parts of a message –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\
Working with Objects: Working with Objects: Messages Messages [2/2][2/2]
Different objects may respond differently Different objects may respond differently to an identical message:to an identical message: bicycle.changeGears(lowerGear) car.changeGears(lowerGear)
The same name and the same argument, The same name and the same argument, but a different method = but a different method = POLYMORPHISMPOLYMORPHISM
A method is defined only in the scope of A method is defined only in the scope of a particular type of object, called classa particular type of object, called class
Polymorphism is also called: Polymorphism is also called: function function overloadingoverloading
Now that we know what an object is all Now that we know what an object is all about, let's look at how we can about, let's look at how we can organizeorganize these objects these objects
Class =Class = A blueprint, or prototype, that A blueprint, or prototype, that defines the variables and the methods defines the variables and the methods common to all objects of a certain kindcommon to all objects of a certain kind
House Plans:House Plans:the architectural drawings the architectural drawings that describe how a house that describe how a house is to be constructedis to be constructed
A House:A House:
The house built from the The house built from the plans is an instance of the plans is an instance of the House Class. The process House Class. The process of building the house is of building the house is called called InstantiationInstantiation
Abstractions Abstractions reveal causes and effects, reveal causes and effects, expose patterns and frameworks and expose patterns and frameworks and separate what's important from what's notseparate what's important from what's not
Abstraction in programmingAbstraction in programming helps you helps you make your ideas concrete in your code make your ideas concrete in your code without obscuring the architecture with without obscuring the architecture with detailsdetails
In procedural languages:In procedural languages: structures and functions are abstractions
A Quick Review:A Quick Review: ““OOP is more a way of thinking than just a OOP is more a way of thinking than just a
programming technique” – “programming technique” – “conceptual tool that you conceptual tool that you use in thinking how to solve a problem”use in thinking how to solve a problem”
Computer Computer objectsobjects form the basis form the basis Objects treated as real life objectsObjects treated as real life objects
Identities Properties Behaviors
Data and functionality Data and functionality encapsulatedencapsulated in an object in an object Data Data hiddenhidden behind methods behind methods
Objects organized in class hierarchies: inheritanceObjects organized in class hierarchies: inheritance Objects interact through messages – methodsObjects interact through messages – methods Polymorphism: the same message has a different Polymorphism: the same message has a different
meaning for different objectsmeaning for different objects
Benefits of Object Oriented Benefits of Object Oriented ProgrammingProgramming
Analysis and Design made easierAnalysis and Design made easier Understanding of code made easierUnderstanding of code made easier Code ReuseCode Reuse Ease of maintenance and enhancement Ease of maintenance and enhancement Simplifies collaborationSimplifies collaboration Fewer and shorter design iterationsFewer and shorter design iterations
““Simulate the functionality of your computer Simulate the functionality of your computer using the object oriented using the object oriented philosophyphilosophy” ”
Draw a diagram of the components present in Draw a diagram of the components present in the computer. What is the flow of information the computer. What is the flow of information between these components? Leverage from between these components? Leverage from previous lectures.previous lectures.
Identify the classes and objects that you Identify the classes and objects that you would need to simulate these components. would need to simulate these components. How do these classes interact?How do these classes interact?
Identify the variables and methods that you Identify the variables and methods that you would assign to each class.would assign to each class.
Due Date: Due Date: Friday, March 5Friday, March 5thth, 2004, 2004
““Core Java, ” Cay S. Horstmann and Gary Core Java, ” Cay S. Horstmann and Gary Cornell, Cornell, Sun MicrosystemsSun Microsystems
““ Thinking in C++Thinking in C++, , ”” Bruce Eckel, Bruce Eckel, http://www.mindview.net/Books/TICPP/Thinhttp://www.mindview.net/Books/TICPP/ThinkingInCPP2e.htmlkingInCPP2e.html
“ “ Introduction to Object Oriented Introduction to Object Oriented Programming, ” Timothy Budd, Programming, ” Timothy Budd, ftp://ftp.cs.orst.edu/pub/budd/oopintro/3rdEftp://ftp.cs.orst.edu/pub/budd/oopintro/3rdEdition/info.htmldition/info.html
LearningLearning Object oriented programming is more a philosophy than Object oriented programming is more a philosophy than
mere technique to develop programs…mere technique to develop programs… This philosophy provides modularity to programsThis philosophy provides modularity to programs Modularity provides openness to change…Modularity provides openness to change… Enables developing complex systemsEnables developing complex systems
Food for ThoughtFood for Thought How will object oriented philosophy help in the future of How will object oriented philosophy help in the future of
software development?software development? How can the object oriented philosophy based on How can the object oriented philosophy based on
modularity be used in your field of specialization?modularity be used in your field of specialization? What changes are required to adapt this philosophy to What changes are required to adapt this philosophy to