Object Oriented Representations


Class, Object, Method, Polymorphism

Q. Explain the following concepts in context of object-oriented representations:

1. Object (Dec.98, Dec. 00, Dec. 02)

1. Object: An object is an instance of a class. It can be uniquely identified by its name and it defines a state, which is represented by the values of its attributes at a particular time. In other words, an object is a special type of variable that stores data and manipulates that data by passing messages to itself. Objects are the basic building blocks in object-oriented systems. An object consists of a limited amount of memory, which contains other objects (data and procedures). They are encapsulated together as a unit and are accessible to that object only. Examples of objects are numbers such as 15, 51, 7.51, strings like 'Universal Teacher Publications', a motor bike, a ship, and so on. Objects are characterized by attributes and by the way they behave when messages are sent to them. All objects belong to some class. They are created by declaring them as instances of an existing class and instantiating instance variables. The class to which an object belongs can be determined by sending it the message "class."


2. Message (Dec.98, June 99, Dec. 00, June 00, Jan. 01, June 03)

Message: Actions are performed in an OOS by sending messages to an object. This corresponds to a function or procedure call in other languages. The messages are formatted strings composed of three parts: a receiver object, a message selector, and a sequence of zero or more arguments. The format of a message is given as

<object><selector><arg1 arg2 …>

The object identifies the receiver of the message. This field may contain an object item or another message which evaluates to an object. The selector is a procedure name. It specifies what action is required from the object. The arguments are objects used by the receiver object to complete some desired task. Messages may also be given in place of an argument since a message always elicits an object as a response.

There are three types of messages: unary, binary, and keyword (n-ary). All three types parse from left to right, but parentheses may be used to determine the order of interpretation. A unary message requires no arguments. For example, 50 as Character, 5 factorial, 'Universal Teacher Publications' size. Binary messages take one argument. Arithmetic operations are typical of binary messages, where the first operand is the receiver, the selector is the arithmetic operation to be performed, and the second operand is the argument. Examples of binary messages are

50 + 10 "an addition message"
10 - 9 "a subtraction message"
22 * 7 "multiplication message"

The most general type of message is the keyword message. These messages have selectors, which consist of one or more keyword identifiers, where each is followed by a colon and an argument. The argument can be an object or any message, but if it is another keyword message, it must be enclosed in parentheses For examples,

5 between: 4 and: 10 "a Boolean test"
aecdb' copyFrom: 2 to: 5 "copies position 2 of the string to position 5"
set1 add: (i + 1) "add new element to set 1"


3. Method (Dec.98, June 99, June 00, Dec. 00)

Methods: Procedures are called methods. They determine the behavior of an object when a message is sent to the object. Methods are the algorithms or sequence of instructions executed by an object. For example, in order to respond to the message 10 + 7, the object 10 must initiate a method to find the sum of the integer numbers 10 and 7. On completion of the operation, the method returns the object 17 to the sending object. Methods are defined much like procedures in other programming languages using the constructs and syntax of the given OOS. The constructs used to build higher level methods are defined in terms of a number of primitive operations and basic methods provided as part of the OOS. The primitives of an OOS are coded in some host language such as an assembler language or C.


4. Class (Dec.98, Dec. 00, Jan. 01, Dec. 02, June 03)

Class: A class is a general object that defines a set of individual (instance) objects, which share common characteristics. For example, the class of balloons contains many individual balloon objects. The class of natural numbers contains many instance objects such as 13, 51, 5, … All objects are instances of some class and classes are subclasses of some higher class, except for a most general root class. Classes can often be divided into subclasses or merged into superclasses. The class of fruit can be divided into citrus and noncitrus, both of which can be further divided. Fruit is part of the superclass of plant-grown foods, which in turn is part of the class of all foods. Classes permit the formation of hierarchies of objects, which can be depicted as a tree or taxonomic structure as illustrated in the following figure.

Objects belonging to the same class have the same variables and the same methods. They also respond to the same set of messages called the protocol of the class.


5. Polymorphism (June 00, Dec. 02)

Polymorphism: Polymorphism is the ability of an entity (for example, variable, function, object, operator) to take a variety of representations. For example, a message containing the selector moveForward could invoke the forward movement of a ship as well as advancing a piece in a game such as checkers. Both classes use the same message template but respond differently. The only requirement is that the message protocol for the two classes be implemented as required for the given class.

 
          AI Contents  
©Universal Teacher Publications Web: www.universalteacherpublications.com.