Functional and Object Oriented Analysis and Design: An Integrated Methodology

Class An abstract class is a class that has no objects, but it has attributes, functions, and subclasses which inherit from it. The definition of such an “empty” class enables us to save the time needed for defining attributes and functions in various classes. For example, in Figure 2.10 we defined the University Workers class. At first glance, it appears that we could have done without it, since every person at the university is one of the three: teacher, student, or administrative worker. However, in this case we would have had to define the shared attributes, relationships, and functions in each of the three classes; the definition of the University Workers as their superclass saves time and prevents duplicities. The state of abstract class can easily change to an ordinary one (i.e., a class that has objects). In our example (Figure 2.10), the University Workers class can be considered abstract only because of the ‘T’ constraint, meaning there are no other kinds of employees in the university but those defined in the subclasses. However, had we chosen to allow other kinds of employees (who have no specific attributes and relationships) their objects could only exist in the superclass. Of course, in that case the ‘T’ constraint must be removed. An abstract class does not have to have a key (since it does not have objects to distinguish between). This is true only if the subclasses have keys of their own, which are different from one another. For example, if a teacher is identified by teacher number, a student by student ID, and an administrative worker by empID (and the ‘T’ constrain holds), then there is not a necessity to define a “super key” for University Workers. If, on the other hand, all types of workers are identified by a universal (national) ID number, it would be preferred to define this attribute as key of the superclass—as demonstrated in Figure 2.10. The Objects Model and the Class Diagram 43 Copyright © 2007, Idea Group Inc. Copying or distributing in print or electronic forms without written permission of Idea Group Inc. is prohibited. Functions A class has functions which can perform actions on its objects. All the functions that can be performed on an object during its lifetime in the system define the object’s “behavior. ” Recall that while the objects of a class are assumed to be stored in a database, it may be assumed that the functions of a class (more precisely, the code of the functions) are stored separately, along with other definitions of the class (especially its attributes). This place is usually called the catalog. As we know, a function has a name. The function’s full name, by which it can be identified, is the name of the class it belongs to, and the function’s name within the class (it means, of course, that the function’s names within a class are unique). A function may also include an output variable, by which the outcome of the operation will be returned to the function that called it, and a list of parameters (arguments) by which the function receives values needed for the execution. We call this part of the function (i.e., the function name and its parameters) signature. The main part of a function is the method, that is, a detailed specification of how the procedure will perform the function. A method can be viewed as a small program, made up of specific commands which are organized in proper process logic, using patterns of structured programming (i.e., sequences, branches, or loops). In addition to ordinary commands which a method performs by itself, it may include messages to other functions, whether belonging to the same class or to other classes. A message includes, as we know, the name of the receiving function (and its class), and it may include parameters through which the function will receive data needed to execute, or an output variable in case the sending method needs to get a result from the receiving message. As an example we bring here the definitions of a class Student and its subclass Graduate Student, each including several attributes and functions. The example is written in C++; it is not the intention to get into the code details, only to demonstrate how functions and methods can be defined. The Student class has several attributes defined as “private. ” It means that they cannot be accessed from outside the class; they are hidden. On the other hand, the functions are defined as “public,” which means that the class objects are accessible through them. Generally, functions too can be defined as private, but only if they may be activated by other functions of that class. The function student, whose name is the same as the class name, is a constructor function, which can create/add a new student object and initialize its attributes. (Similarly, we can also define a destructor function, capable of deleting a student object.)