CS 23001 CS II Data Structures and Abstraction
CS 23001 CS II: Data Structures and Abstraction Abstract Data Types (ADT) and the Class Construct Xiang Lian Department of Computer Science Kent State University Email: xlian@kent. edu Homepage: http: //www. cs. kent. edu/~xlian/ 1
Objectives • In this chapter, you will – Become aware of reasons for using objects and classes – Become familiar with classes and objects 2
Introduction • We humans are very good in recognizing and working with objects, such as a pen, a dog, or a human being • We learned to categorize them in such a way that make sense to us. We may categorize them as animate object, inanimate objects, pets, friends, etc. 3
Introduction (cont'd) • We sometimes classify objects based on their attributes, for example, green apples or red apples, students or professors, etc. • If you think about it, each object has many attributes. If I ask you list the attributes of an orange, you probably could list many things such as color, shape, weight, smell, etc. 4
Introduction (cont'd) • In addition to attributes, all objects exhibit behaviors • A dog eats, barks, wags its tail, plays, and begs – A dog exhibits many more other behaviors than this short list • Another thing we need to remember about objects is that objects interact between each other 5
Objects • Objects are packages that contain data and functions (methods) that can be performed on the data 6
Objects (cont'd) • Data could be considered to be attributes and functions are considered to be behaviors of the object • We can say that the attributes and behaviors are encapsulated into an object 7
Objects (cont'd) • The objects interact between each other through their interfaces • As an example a date object may have: – a set of data consisting of month, day and year; – a set of methods, e. g. , assigning date, displaying the date, yesterday and tomorrow, and so on 8
A Class is Like a Type • Similar to int, double, float, bool, etc. • You cannot use a class until an instance (an object) of it is created • A class has properties (attributes) and methods – Member variables – Member functions 9
Point Example • … 10
- Slides: 10