Object Oriented Programming in Matlab - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Object Oriented Programming in Matlab

Description:

House plans: the architectural drawings that describe how a house is to be ... or properties), one can create a new house object from the same class (plans) ... – PowerPoint PPT presentation

Number of Views:866
Avg rating:3.0/5.0
Slides: 11
Provided by: jimc3
Category:

less

Transcript and Presenter's Notes

Title: Object Oriented Programming in Matlab


1
Object Oriented Programming in Matlab
Learning Objectives Were now going to introduce
you to some advanced computing concepts, and
well illustrate a simple application that
creates a new data type called an ASSET with
subtypes.
Topics
  • 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.

2
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
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
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 MatlabgtProgramminggtClass
    es Objects in online help docs
  • Were going to go over only the very basics of
    OOP in Matlab
  • you can pursue more details on your own (in
    Matlab or Java)
  • well illustrate OOP concepts by examining how
    Matlabs Handle Graphics can be used to extend
    its plotting and visualization capabilities.

5
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
What is an Object - contd
  • 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
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
Matlabs Built-in Classes
  • Matlabs 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 (_at_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)

ARRAY
char
NUMERIC
java class
cell
function handle
structure
user class
int8, uint8, int16, uint16, int32, uint32
single
double
sparse
9
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
  • well look further into this in the next lecture
  • Well also look closely at operator overloading,
    especially for Matlabs basic classes

10
Summary
  • Learning Objectives
  • OOP concepts
  • Summary
  • Action Items
  • Review the lecture
  • Consult the reference material
  • Consider how this might be extended to other
    applications
Write a Comment
User Comments (0)
About PowerShow.com