MATLAB Object-Oriented Programming

(Joyce) #1

to all cases that use this code. Step 2 could be defined syntactically, but not implemented,
leaving the specialized implementation to the classes that you then derive from this base
class.


Step 1
function checkInputs()
% actual implementation
end


Step 2
function results = computeOnFirstArg()
% specify syntax only
end


Step 3
function transformResults()
% actual implementation
end


Step 4
function out = checkOutputs()
% actual implementation
end


The code in the base class is not copied or modified. Classes you derive from the base
class inherit this code. Inheritance reduces the amount of code to be tested, and isolates
your program from changes to the basic procedure.


Defining Consistent Interfaces


The use of a class as the basis for similar, but more specialized classes is a useful
technique in object-oriented programming. This class defines a common interface.
Incorporating this kind of class into your program design enables you to:



  • Identify the requirements of a particular objective

  • Encode requirements into your program as an interface class


Reducing Complexity


Objects reduce complexity by reducing what you must know to use a component or
system:



  • Objects provide an interface that hides implementation details.


Why Use Object-Oriented Design
Free download pdf