14-440-127+Lecture+11 - 14:440:127 Introduction to...

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

View Full Document Right Arrow Icon
14:440:127– Introduction to Computers for Engineers Notes for Lecture 11 Rutgers University, Spring 2010 Instructor- Blase E. Ur 1 Object Oriented Programming- I’m Down With OOP http://www.cs.ubc.ca/~murphyk/Software/matlabTutorial/html/objectOriented.html contains a good primer for this section since it’s too new to be covered in your book. You can also see the official Matlab page at: http://www.mathworks.com/products/matlab/object_oriented_programming.html Sometimes when you’re designing a Matlab program, you come across a situation where it’s easiest to think about the type of data you’re using as some sort of ‘object’ or ‘thing.’ For instance, if you were working for the New Jersey Devils hockey team and creating a program to track everything you know about the players, you could think about a ‘hockey player’ as the object you’re creating. Each ‘hockey player’ has a number of properties, or variables– his or her name, age, address, weight, and so on. You might recall the ‘struct’ data type, which I previously mentioned as a natural fit for databases like this in terms of having different fields for each variable. However, we can now use a paradigm called object-oriented programming (OOP for short) to go a step beyond ‘structs.’ Whereas each ‘struct’ was basically just a collection of different variables all tied together, an ‘object’ also has functions associated with that variable. For instance, for our ‘hockey player,’ we might have functions to display that player’s statistics, or perhaps to trade the player. Having the ability to create functions for our object is the main difference between objects and structs. We define objects by creating a ‘class.’ To continue with our example, we could create a class called ‘hockey- player.’ We then need to list all of the variables each ‘hockeyplayer’ will have and define the functions that hockey player would have inside a class definition file, which in general appear as follows (replacing everything all in capitals): classdef CLASSNAME properties % variables
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/20/2011 for the course ENGINEERIN 127 taught by Professor Finch during the Spring '08 term at Rutgers.

Page1 / 6

14-440-127+Lecture+11 - 14:440:127 Introduction to...

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

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