70 likes | 85 Views
This chapter explores the concepts of objects, classes, subclasses, and class hierarchy in object-oriented programming languages. Learn about encapsulation, methods, messages, and multiple inheritance. Understand the properties and operations of binary trees and binary search trees.
E N D
CS 331, Principles of Programming Languages Chapter 7 Object-Oriented Programming
What is an object? • Represents some important entity in the application • Has external and internal properties, which include some • data, and • operations to be applied to that data • May be one of several similar objects
Terminology • An object is an encapsulation of data and operations • A class is a set of objects that have the same or similar properties (i.e. data and operations) • A subclass is a subset of a class, with additional properties
More Terminology • An individual object belonging to a given class is an instance of that class • A method is a procedure body that implements an operation • A message is a request to execute a method • note that a message may or may not involve inter-process communication
Class Hierarchy? • A subclass is derived from at least one parent class • operations in the class can be applied to objects in any subclass, unless redefined • Instances of subclass objects may have additional operations that can be applied • Some OOPLs support multiple inheritance, where a class may have more than one parent
Classes and subclasses • Tree • node root(t: tree) • height(n: node) • n_of_immediate_descendants(n: node) • Binary tree • left_child(n: node) right_child(n: node) • Binary search tree • tree insert(key: K, value: someDataType)
Another Parent Class? • Class SearchableThing • insert(K: key, newData:someDataType) • someDataType retrieve(K: key) • Boolean search(K: key) • cleanOut(K: key) • The Binary search tree class may have the same properties as Binary Tree and Searchable Thing