lecture26 Classes

lecture26 Classes - 1 © Janice Regan CMPT 128 February...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1 © Janice Regan, CMPT 128, February. 2007 CMPT 128: Introduction to Computing Science for Engineering Students Classes © Janice Regan, CMPT 128, February 2007 2 Abstract Data Types Programmers using the data type don’t need to know the details of how it is implemented Programmers using the data type just need to know its interface An ADT is a collection of data values together with set of basic operations defined for the values ADT’s may be language-independent We implement our own ADT’s in C++ with classes Other languages implement ADT’s as well Data types such as int are also ADT’s © Janice Regan, CMPT 128, February 2007 3 Encapsulation Any data type includes Data (range of data) Operations (that can be performed on data) Example: int data type has: Data: +-32,767 Operations: +,-,*,/,%,logical,etc. Same with classes But WE specify data, and the operations (methods) to be allowed on our data! © Janice Regan, CMPT 128, February 2007 4 Objects and classes How do we make classes and objects in our C++ code (or in code using some other object oriented language) Define a class that contains all the attributes and methods of the type of object. (just like we defined a structure) To make a particular object of a class declare a instance of that class and associate it with an identifier (name) The instance can be made in any other class, structure or function, and used within the defined scope Many instances (objects) of the same class can be declared, just as many variables of a particular type can be declared In fact a class is a user defined type !! © Janice Regan, CMPT 128, February 2007 5 Object Oriented vs. Procedural Up to now we have been thinking in terms of procedures. To solve a problem we thought about breaking the problem down into different tasks, each implemented as a procedure (function) Each function was implemented using series of steps (an algorithm) Now lets think in a different way, using objects © Janice Regan, CMPT 128, February 2007 6 Object Oriented vs. Procedural Now lets think in a different way, using objects An object is a type of thing An object includes information ( attributes ) An object includes functions or ways to manipulate those attributes ( methods ) We model our system by identifying all the objects in it and how they communicate with each other (algorithms are still used to explain how to implement each method) Each object encapsulates (hides) the complexity associated with its attributes and methods from the rest of the system © Janice Regan, CMPT 128, February 2007 7 Object Example Let's think about building a software system to run an automatic teller machine. An example of a type of object in this system might be a bank client A bank client has associated information (attributes or data) Name and address, list of accounts The system can do things to a bank client (methods) Create a new client Delete an old client Add a new account to a clients list … © Janice Regan, CMPT 128, February 2007...
View Full Document

This note was uploaded on 05/18/2010 for the course CMPT 128 taught by Professor Regan during the Spring '08 term at Simon Fraser.

Page1 / 36

lecture26 Classes - 1 © Janice Regan CMPT 128 February...

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

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