{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

26 Classes and OOP

26 Classes and OOP - 26 Classes and Object Oriented...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
25 - OOP - 1 26 - Classes and Object Oriented Programming Motivation In the programming we have done so far, we have been performing what is known as functional programming . In this framework, we have focused our efforts (mostly) on writing functions with the understanding that the input into each function will be a particular type of data. In Object Oriented Programming , the focus is reversed. We concentrate on our data and adjust our functions to fit One advantage of Object Oriented programming is that we can aggregate all kinds of data together into a single “variable”. This is called data encapsulation , and is similar to the work we did with structures. In the OOP world, a variable is usually called an instance of a class , or an object . A class is a group of many instances of data which have the same structure. Data in an object is protected because users cannot access it directly. They have to use a function (called a method ) which is specifically designed for the class. Definitions To make this more transparent, some definitions are needed: An object is an aggregate of data. (It is also called an instance of a class. ) A class is a template for an object. A method is a function which is associated with and operates on objects of a given class An Abstract Data Type is the definition of the data structure of the object together with the methods of the class. Defining ADT’s is often the first step in creating a software system. In MATLAB, we need a minimum of two items to define a class: 1. An m-file called a constructor method which sets up the data template for our class and 2. A display method so that objects of the class can be printed out and examined. To make a useful class, we will generally have to have many other methods. All of the files for a class must be stored together in a directory which starts with the “@” symbol and is followed by the class name. The constructor method must be the same as the class name (followed by a ‘.m’ ). The display method must be called display.m
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
25 - OOP - 2 Example: Points in two dimensions Suppose you need to implement a data structure to represent a point in two dimentions.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

26 Classes and OOP - 26 Classes and Object Oriented...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online