Inheritance in Matlab Classes E177 February 14, 2008 Copyright 2005-2008, Andy Packard. This work is licensed.

Slides:



Advertisements
Similar presentations
Scientific Communication Life-cycle model
Advertisements

Outline 1 Introduction 2 Base Classes and Derived Classes 3 protected Members 4 Relationship between Base Classes and Derived Classes 5 Case Study: Three-Level.
Copyright 2006 Oxford Consulting, Ltd1 February C++ Inheritance Data Abstraction and Abstract Data Types Abstract Data Type Encapsulated data.
C++ Inheritance Gordon College CPS212. Basics OO-programming can be defined as a combination of Abstract Data Types (ADTs) with Inheritance and Dynamic.
Trees UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
Foundations of (Theoretical) Computer Science
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.1: DFA’s) David Martin With some modifications.
Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.2: NFA’s) David Martin With some modifications.
Computer Science I Inheritance Professor Evan Korth New York University.
Solving ODEs UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Functions UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
1 Ben Woelk RIT Information Security Office Advancing Digital Self Defense Establishing a Culture of Security Awareness at the Rochester Institute of Technology.
Numerical Integration UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the.
Solving Linear Equations UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the.
Fall 2006AE6382 Design Computing1 OOP: Creating a Class More OOP concepts An example that creates a ASSET class and shows how it might be used Extend the.
Debugging UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Time Complexity UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Regression UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Simulink SubSystems and Masking April 22, Copyright , Andy Packard. This work is licensed under the.
Cell Arrays UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Recursion and Induction UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the.
Black Box Software Testing Copyright © 2003 Cem Kaner & James Bach 1 Black Box Software Testing Spring 2005 PART 7 -- FUNCTION TESTING by Cem Kaner, J.D.,
Sorting UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Script Files UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Objects and Classes UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Numerical Differentiation UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under.
Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.
IEEE Arithmetic UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Searching UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Struct Arrays UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Inheritance Inheritance allows a programmer to derive a new class from an existing one The existing class is called the super class, or parent class,
Polynomials UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
Basics of Matlab UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Intro to Simulink April 15, Copyright , Andy Packard. This work is licensed under the Creative Commons.
Simulink Model Commands April 11, Copyright 2005, Andy Packard. This work is licensed under the Creative.
Root Finding UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Fall 2006AE6382 Design Computing1 OOP Programming in Matlab Review our ASSET class and study how it might be used as a parent for other classes Extend.
Get/Set Methods UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Intro to Simulink Modified by Gary Balas 20 Feb 2011 Copyright , Andy Packard. This work is licensed under.
Introduction to CMex E177 April 25, Copyright 2005, Andy Packard. This work is licensed under the Creative.
E177, Rules of Interruptibility of Callbacks March 4, Copyright , Andy Packard. This work is licensed.
Copyright Crash Course Laura Rivera EDTC
The Object-Oriented Thought Process Chapter 03
Black Box Software Testing Spring 2005
OOP: Creating a Class Topics More OOP concepts
FAST TRACKING IN THE IEEE
Introduction to Java E177 April 29, me. berkeley
Black Box Software Testing Spring 2005
Welcome to course DT2350 Human Perception for Information Technology
For/Switch/While/Try UC Berkeley Fall 2004, E77 me
Inheritance Inheritance allows a programmer to derive a new class from an existing one The existing class is called the super class, or parent class,
ME190L Nyquist Stability Criterion UC Berkeley Fall
Road Map Inheritance Class hierarchy Overriding methods Constructors
Reusable Graphics Objects UC Berkeley Fall 2004, E77 me
Understanding Inheritance
Class Info E177 January 22, me. berkeley
Regular Expressions: Searching strings for patterns April 24, 2008 Copyright , Andy Packard and Trent Russi. This work is licensed under the Creative.
E177, Graphics Objects in Matlab February 26, me
@ReferAssignGetSet February 21, me. berkeley
Black Box Software Testing Fall 2004
Black Box Software Testing Fall 2005 Overview – Part 1 of 3
Black Box Software Testing 2004 Academic Edition
Class Intro/TDD Intro 8/23/2005
E177, Reference/Assignment for Classes: Intro February 12, Copyright , Andy Packard. This work.
Function Handles UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Basics of Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Presentation transcript:

Inheritance in Matlab Classes E177 February 14, Copyright , Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Classes Recall, classes give data an identity, and associate functions to the identity. A class can also inherit some parts of its identity and associated functions from another class. This is called inheritance, and allows for hierarchical layout of classes, and promotes reuse of methods. referred to as the child class referred to as the parent class

@vehicle class (front wheel steering) Simple constructor vehicle class function M = vehicle(xyloc,v,theta,omega,wh) M.Location = xyloc; % 2-by-1 M.Velocity = v; % 2-by-1 M.Orientation = theta; % 1-by-1 M.AngularRate = omega; % 1-by-1 M.RectDim = wh; % 2-by-1 M = class(M,’vehicle’); An ismoving method function B = ismoving(A) B = norm(A.Velocity)>0; An isrearwheelskidding method… some relation between Orientation and Velocity

@car class Simple constructor car class, inheriting vehicle function M = car(BP,SA,DT,R,xy,v,th,om,wh) Veh = vehicle(xy,v,th,om,wh); M.BreakPressure = BP; M.SteeringAngle = SA; M.DriveTorque = DT; M.WheelRadius = R; M = class(M,’car’,Veh); A = car(2.4,…); class(A) isa(A,’car’), isa(A,’vehicle’), ismoving(A) Make M an object of class car Inherit data from Veh, and all methods from class(Veh)

SomeCarMethod.m A method for objects of class car can reference and modify the inherited vehicle object function M = SomeCarMethod(A) % This function can access fields… A.BreakPressure % class=double A.SteeringAngle % class=double A.DriveTorque % class=double A.WheelRadius % class=double A.vehicle % class=vehicle Example: FrontWheelSlipAngle, relation between SteeringAngle, Orientation, Velocity

Scope for inherited classes At this point, we have Consider V1 = vehicle([2;3],[10;3],1.2,0.1,[1;4]); C1 = car(0,0.2,100,190,[1;2],[5;6],1,0,[2;4]); ismoving(V1) ismoving(C1) SomeCarMethod(V1) SomeCarMethod(C1) car.m vehicle.m ismoving.m Inside ismoving, only the fields of vehicle class can be accessed directly, even though input arg is a car object.

@bike class Simple constructor bike class, inheriting vehicle function M = bike(FCR,RCR,F,R,SA,RA,… xy,v,theta,wh) Veh = vehicle(xy,v,theta,wh); M.FrontChainRing = FCR; M.RearChainRing = RCR; M.FrontGear = F; M.RearGear = R; M.SteeringAngle = SA; M.RollAngle = RA; M = class(M,’bike’,Veh);

@wheelchair class Simple constructor wheelchair class, inheriting vehicle function M = wheelchair(RW,Lw,Rw,… xy,v,theta,wh) Veh = vehicle(xy,v,theta,wh); M.RearWheelRadius = RWR; M.LeftWheelRate = Lw; M.RightWheelRate = Rw; M = class(M,’wheelchair’,Veh); Front wheels are very small and light, so perhaps… function A = FrontWheelSlipAngle(W) A = 0;

Folder layout Each class has a constructor and methods. car.m vehicle.m ismoving.m wheelchair.m bike.m incrementFrontChainRing.m

@ReferAssignGetSet Many ideas of get, set, subsref, subsasgn will to carry over to all classes we write. For example, –Reference of M.Value is the same as get(M,’Value’) –Multi-depth subsref has specific recursive meaning –Assignment of M.Value=B is the same as set(M,’Value’,B) –Multi-depth subsasgn has specific recursive meaning –In some cases, () reference and assignment should be handled by the built-in methods for Matlab arrays –set should work with or without output arguments –Special Matlab-like conventions for get and set should be followed Calls with 1-input argument Property names can be partially specified Multiple args in set(A,P1,V1,P2,V2) This is a good motivation to write a class that handles all of this functionality, and all other classes will simply inherit this.

@ReferAssignGetSet Questions/Options for a given class –Is property reference allowed, as in Object.Property –Is property assignment allowed, as in Object.Property = Value –Is () reference allowed, as in Object(Idx1,Idx2) if so, are builtin methods used, or does the class programmer supply the reference method? –Is () assignment allowed, as in Object(Idx1,Idx2) = Value if so, are builtin methods used, or does the class programmer supply the assignment method? –Is {} reference allowed, as in Object{Idx1,Idx2} if so, are builtin methods used, or does the class programmer supply the reference method? –Is {} assignment allowed, as in Object{Idx1,Idx2} = Value if so, are builtin methods used, or does the class programmer supply the assignment method? –Does set use assignin when called with no output arguments? set(A,Prop,Value) %uses inputname, overwrites A A = set(A,Prop,Value) % overwrites A, directly B = set(A,Prop,Value) % A unchanged