CS304 - Object Oriented Programming
CS304 - Object Oriented Programming
**ANSWER: [Booch 91, p. 45] defines: "Encapsulation is the process of hiding all of
the details of an object that do not contribute to its essential characteristics." [Coad 91,
1.1.2] defines: "Encapsulation (Information Hiding). A principle, used when developing
an overall program structure, that each component of a program should encapsulate or
hide a single design decision... The interface to each module is defined in such a way as
to reveal as little as possible about its inner workings. [Oxford, 1986]" Some languages
permit arbitrary access to objects and allow methods to be defined outside of a class as in
conventional programming. Simula and Object Pascal provide no protection for objects,
meaning instance variables may be accessed wherever visible. CLOS and Ada allow
methods to be defined outside of a class, providing functions and procedures. While both
CLOS and Ada have packages for encapsulation, CLOS's are optional while Ada's
methodology clearly specifies class-like encapsulation (Adts). However most
objectoriented
languages provide a well defined interface to their objects thru classes. C++ has
a very general encapsulation/protection mechanism with public, private and protected
members. Public members (member data and member functions) may be accessed from
anywhere. A Stack's Push and Pop methods will be public. Private members are only
accessible from within a class. A Stack's representation, such as a list or array, will
usually be private. Protected members are accessible from within a class and also from
within subclasses (also called derived classes). A Stack's representation could be declared
protected allowing subclass access. C++ also allows a class to specify friends (other
(sub)classes and functions), that can access all members (its representation). Eiffel 3.0
allows exporting access to specific classes.
**ANSWER: A class is a general term denoting classification and also has a new
meaning in object-oriented methods. Within the OO context, a class is a specification of
structure (instance variables), behavior (methods), and inheritance (parents, or recursive
structure and behavior) for objects. As pointed out above, classes can also specify access
permissions for clients and derived classes, visibility and member lookup resolution. This
is a feature-based or intensional definition, emphasizing a class as a
descriptor/constructor of objects (as opposed to a collection of objects, as with the more
classical extensional view, which may begin the analysis process). Original Aristotlean
classification defines a "class" as a generalization of objects: [Booch 91, p93] "a group,
set, or kind marked by common attributes or a common attribute; a group division,
distinction, or rating based on quality, degree of competence, or condition".
**ANSWER: Meta-Class is a class' class. If a class is an object, then that object must
have a class (in classical OO anyway). Compilers provide an easy way to picture Meta-
Classes. Classes must be implemented in some way; perhaps with dictionaries for
methods, instances, and parents and methods to perform all the work of being a class.
This can be declared in a class named "Meta-Class". The Meta-Class can also provide
services to application programs, such as returning a set of all methods, instances or
parents for review (or even modification). [Booch 91, p 119] provides another example in
Smalltalk with timers. In Smalltalk, the situation is more complex
**ANSWER: The importance of abstraction is derived from its ability to hide irrelevant
details and from the use of names to reference objects. Abstraction is essential in the
construction of programs. It places the emphasis on what an object is or does rather than
how it is represented or how it works. Thus, it is the primary means of managing
complexity in large programs.
**ANSWER: The method overloading is the ability to define several methods (in same
class) all with the same name but different on the basis of i) number of parameters ii)
types of parameters.
**ANSWER: Polymorphism is a generic term that means 'many shapes'. More precisely
Polymorphism means the ability to request that the same operations be performed by a
wide range of different types of things.
**ANSWER: Ability of a new class to be created, from an existing class by extending it,
is called inheritance.
**ANSWER: When inheritance is used to create a new class from another, the new class
is called the subclass or derived class, and the class from which it was derived is called
the base class.
**ANSWER: A concrete class is one that can be used to directly create, or instantiate
objects, unlike an abstract base class which can only be used as a base class for other
classes which eventually lead to concrete classes
**ANSWER: Objects are miniature programs, consisting of both code and data. The
code consists of a series of member functions. The data items are called data members.
**ANSWER: Objects are complete, miniature programs and, like any good programs,
have well defined initialization and termination phases. They have special routines (i.e.
member functions ) to look after this. The initialization routine is called the constructor,
and C++ ensures that every object is properly initialized by calling its constructor. The
designer of the object can have more than one constructor, a situation called overloading
and then the compiler will select between them depending on exactly what arguments are
passed to the constructor function. However there must always be a default constructor,
to be used when no information is supplied.
**ANSWER: The termination routine is called the destructor, and C++ will provide a
default if none is supplied. If, during the lifetime of the object, it uses heap memory then
the designer of the object must provide a destructor function to release such memory to
avoid a memory leak.
**ANSWER: Local variables can only be accessed within the function, or more
specifically the compound statement in which they are declared. Another way to put this
is to say they have local scope.
**ANSWER: A pointer is a variable that holds the address of another variable or object.
**QUESTION: What is meant by protected?
**ANSWER: The protected keyword in the class statement means that the following
members of the class are not available to users of the objects of the class, but can be used
by any subclass that inherits from it, and consequently forms part of its implementation.
1. Abstract class : A class that can only be used as a base class for some other
class. A class is abstract if it has at least one pure virtual function.
6. agent: : An object that can both initiate behavior in other objects, as well as
be operated upon by other objects.
13. array section: : A subobject that is an array and is not a defined type
component.
15. assignment operator: : The equal symbol, “=”, which may be overloaded
by a user.
17. base class: : A previously defined class whose public members can be inherited
by another class. (Also called a super class.)
18. behavior sharing: : A form of polymorphism, when multiple entities have the
same generic interface. This is achieved by inheritance or operator overloading.
20. bintree: : A tree structure where each node has two child nodes.
25. class diagram: : A diagram depicting classes, their internal structure and
operations, and the fixed relationships between them.
26. class inheritance: : Defining a new derived class in terms of one or more base
classes.
27. class: : An abstraction of an object that specifies the static and behavioral
characteristics of it, including their public and private nature. A class is an ADT
with a constructor template from which object instances are created.
28. concrete class: : A class having no abstract operations and can be
instantiated.
29. constructor: : An operation, by a class member function, that initializes a newly
created instance of a class.
30. container class: : A class whose instances are container objects. Examples
include sets, arrays, and stacks.
31. container object: : An object that stores a collection of other objects and
provides operations to access or iterate over them.
32. data hiding: : The concept that some variables and/or operations in a module
may not be accessible to a user of that module; a key element of data abstraction.
33. information hiding: : The principle that the state and implementation of an object
should be private to that object and only accessible via its public interface.
34. inheritance: : The relationship between classes whereby one class inherits part or
all of the public description of another base class, and instances inherit all the
properties and methods of the classes which they contain.
35. instance: : A individual example of a class invoked via a class constructor.
36. instantiation: : The process of creating (giving a value to) instances from classes.
37. interaction diagram: : A diagram that shows the flow of requests, or messages
between objects.
38. interface: : The set of all signatures (public methods) defined for an object.
39. intrinsic constructor: : A class member function with the same name as the
class which receives initial values of all the data members as arguments.
40. Is-A: : A relationship in which the derived class is a variation of the base class.
41. linked list: : A data structure in which each element identifies its predecessor
and/or successor by some form of pointer.
42. member data: : Variables declared as components of a defined type and
encapsulated in a class.
43. member function: : Subprograms encapsulated as members of a class.
44. message passing: : The philosophy that objects only interact by sending
messages to each other that request some operations to be performed.
45. message: : A request, from another object, for an object to carry out one of its
operations.
46. method: : A class member function encapsulated with its class data members.
47. object : : A concept, or thing with crisp boundaries and meanings for the
problem at hand; an instance of a class.
48. object diagram: : A graphical representation of an object model showing
relationships, attributes, and operations.
49. object-oriented (OO): : A software development strategy that organizes
software as a collection of objects that contain both data structure and behavior.
50. object-oriented programming (OOP) : Object-oriented programs are objectbased,
class-based, support inheritance between classes and base classes and
allow objects to send and receive messages.
51. operation: : Manipulation of an object’s data by its member function when it
receives a request.
52. operator overloading: : A special case of polymorphism; attaching more
than one meaning to the same operator symbol. ‘Overloading’ is also sometimes
used to indicate using the same name for different objects.
53. overloading: : Using the same name for multiple functions or operators in a single
scope.
54. overriding: : The ability to change the definition of an inherited method or
attribute in a subclass.
55. parameterized classes: : A template for creating real classes that may differ
in well-defined ways as specified by parameters at the time of creation. The
parameters are often data types or classes, but may include other attributes, such
as the size of a collection. (Also called generic classes.)
56. pointer: : A single data object which stands such as an array, or defined type.
57. polymorphism: : The ability of an function/operator, with one name, to refer
to arguments, or return types, of different classes at run time.
58. private: : That part of an class, methods or attributes, which may not be
accessed by other classes, only by instances of that class.
59. protected: : (Referring to an attribute or operation of a class in C++) accessible
by methods of any descendent of the current class.
60. public: : That part of an object, methods or attributes, which may be
accessed by other objects, and thus constitutes its interface.
61. super class: : A class from which another class inherits.