Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2006AE6382 Design Computing1 Object Oriented Programming in Matlab Intro to Object- Oriented Programming (OOP) An example that creates a ASSET class.

Similar presentations


Presentation on theme: "Fall 2006AE6382 Design Computing1 Object Oriented Programming in Matlab Intro to Object- Oriented Programming (OOP) An example that creates a ASSET class."— Presentation transcript:

1 Fall 2006AE6382 Design Computing1 Object Oriented Programming in Matlab Intro to Object- Oriented Programming (OOP) An example that creates a ASSET class and shows how it might be used Extend the ASSET class to subclasses of STOCKS, BONDS and SAVINGS. Learning Objectives We’re now going to introduce you to some advanced computing concepts, and we’ll illustrate a simple application that creates a new data type called an ASSET with subtypes. Topics

2 Fall 2006AE6382 Design Computing2 Object-Oriented Programming Object-oriented programming has become a focus of computer science in recent years… –Simula67, SmallTalk, Objective C, C++ and Java are OOP languages –OOP is a key part of the first CS courses OOP keeps you from getting into certain kinds of treacherous problems and tends to foster more reliable coding practices –stimulates a modular coding approach –allows you to hide details from inadvertent alterations –lets you create a hierarchical code structure –But often leads to complex and confusing class libraries

3 Fall 2006AE6382 Design Computing3 What is OOP OOP is part of an on-going effort to add more discipline and organization to programming –it is incorporated to varying degrees in a number of languages –Matlab incorporates OOP While the basic OOP concept is simple, the practical execution can often seem lost in many details! The 4 fundamental OOP characteristics –Abstraction: refine away unimportant details and describe an object by only the data that is important to the task at hand. –Encapsulation: operations must be tightly associated with the data on which they can operate –Inheritance: a hierarchical structure can be effectively employed to describe data and the operations on it –Polymorphism: using the same name to refer to similar methods to handle different kinds of data

4 Fall 2006AE6382 Design Computing4 Matlab and OOP Matlab makes extensive use of OOP at all levels of its design and construction… –much of the basic user programming touches on parts of this but most is well-hidden (to retain the original power of the language) –but it is accessible to programmers when needed –see Chapter 33 in MM7 and Matlab>Programming>Classes & Objects in online help docs We’re going to go over only the very basics of OOP in Matlab –you can pursue more details on your own (in Matlab or Java…) –we’ll illustrate OOP concepts by examining how Matlab’s Handle Graphics can be used to extend its plotting and visualization capabilities.

5 Fall 2006AE6382 Design Computing5 What is an Object? Objects (physical or not) have properties and behaviors –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… –Employee:Properties = SSN, age, gender, … Behaviors = setName, getLastname, calcPay… Properties: information about the object Behaviors: methods to set, get and process properties

6 Fall 2006AE6382 Design Computing6 What is an Object - cont’d OOP lets us create: –a data type –along with the set of operations that can be performed on this data type –this helps us avoid using wrong operations on given data and getting meaningless results A Class: –description of the structure of the new data type (called fields) –the set of operations (called methods or functions) defined for this data type An Object: –a variable having a specific class –Matlab has certain built-in classes –but you can easily define your own

7 Fall 2006AE6382 Design Computing7 Examples Sometimes the differences between classes and objects gets confusing… Example 1: –House plans: the architectural drawings that describe how a house is to be constructed are a House Class –A house: the house built from the plans is an Object or an Instance of the House Class; the process of building the house is called Instantiation of the class. Note that by changing some of the dimensions (fields or properties), one can create a new house object from the same class (plans). Example 2: –Flowchart: provides the plans for a program (the Class) –Program: written from the flowchart is an instance of the class (an object)

8 Fall 2006AE6382 Design Computing8 Matlab’s Built-in Classes Matlab’s built-in classes: –others in additional Toolboxes You can define your own Matlab classes: –data structure (the fields) is a Matlab struct –methods (functions) are stored in special directory (@classname) that is a subdirectory of a directory in the Matlab path –a constructor is a method that is used to create an object (an instance of a class) charNUMERICjava class cellfunction handle int8, uint8, int16, uint16, int32, uint32 singledouble sparse user class structure ARRAY

9 Fall 2006AE6382 Design Computing9 Summary… OOP will let us create an entirely new data types in Matlab –this is done by creating a class to define this data type –we must also create all the methods (functions) that can be used with this special data type –the internal details are hidden inside the class What could we do with this new class? –some engineering functions require use of special data sets and associated methods: this is a good application and you will find this in some of the toolboxes –we can define subclasses to create a data hierarchy –we’ll look further into this in the next lecture We’ll also look closely at operator overloading, especially for Matlab’s basic classes

10 Fall 2006AE6382 Design Computing10 Summary Action Items Review the lecture Consult the reference material Consider how this might be extended to other applications Learning Objectives OOP concepts Summary


Download ppt "Fall 2006AE6382 Design Computing1 Object Oriented Programming in Matlab Intro to Object- Oriented Programming (OOP) An example that creates a ASSET class."

Similar presentations


Ads by Google