lecture26 Classes - CMPT 128 Introduction to Computing...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 © Janice Regan, CMPT 128, February. 2007 CMPT 128: Introduction to Computing Science for Engineering Students Classes
Image of page 1

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

View Full Document Right Arrow Icon
© 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
Image of page 2
© 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!
Image of page 3

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

View Full Document Right Arrow Icon
© 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 !!
Image of page 4
© 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
Image of page 5

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

View Full Document Right Arrow Icon
© 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
Image of page 6
© 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 …
Image of page 7

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

View Full Document Right Arrow Icon
© Janice Regan, CMPT 128, February 2007 8 Another object
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern