J.E.D.I
• An applicant submits a club membership application to the club staff. • A club staff schedules an applicant for a mock try-outs.
• A coach assigns an athlete to a squad. • A squad can be a training squad or a competing squad.
• Teams are formed from a squad.
2.1.2 Encapsulation
Encapsulation is also known as information hiding. It localizes features of an entity into a single blackbox abstraction, and hides the implementation of these features behind
an interface. It allows other objects to interact with one another is such a way that they dont need to know how the implementation fulfills the interface. This is achieved
through the objects message interface. This interface is a set of pre-defined operations used so that other objects can communicate with it. It ensures that data
within the attributes of the object are accessible through an objects operation. No other object can directly access these attributes, and change their values.
Consider the interaction among objects in Figure 2.1 where a coach JP assigns an athlete Joel to a squad. updateSquad is the message interface that changes the
value of the squad attribute of the athlete Joel. Notice, that the change will only occur when the coach JP executes assignToSquad which triggers a request to updateSquad
Training of the squad attribute Joels. The coach JP does not need to know how the athlete Joel updates the squad but is assured that the method is executed.
Encapsulation reduces the ripple effect of changes on codes, where a change in one objects implementation will cause another change in another objects implementation
and so on. With encapsulation, one can change the implementation without changing the other objects implementation as long as the interface is unchanged. Thus,
encapsulation offers two kinds of protection to objects: protection against corruption of internal state and protection against code change when another objects implementation
changes.
2.1.3 Modularity
Modularity is the physical and logical decomposition of large and complex things into small and manageable components. These components can be independently developed
as long as their interactions are well-understood. The concepts of packages, subsystems and components in object-orientation support modularity. They will be
explained further in the succeeding sections of this chapter.
Modularity, like abstraction, is another way of managing complexity. Because it breaks something that is large and complex into smaller manageable components, it makes it
easier for a software engineer to manage and develop the software by managing and developing these smaller components. Then, iteratively integrate them.
For example, Ang Bulilit Liga case study can be divided into smaller subsystems as shown in Figure 2.2.
Software Engineering 38
J.E.D.I
2.1.4 Hierarchy
Hierarchy can be any ranking of ordering of abstraction into a tree-like structure. There are different kinds of hierarchy, and they are listed below.
• Aggregation • Class
• Containment • Inheritance
• Partition • Specialization
• Type Figure 2.3 shows an example of the Squad Hierarchy.
Software Engineering 39
Figure 2.2 Ang Bulilit Liga Subsystems
Ang Bulilit Liga Squad and Team System
Club Membership Maintenance
System Coach Information
Maintenance System
Squad and Team Maintenance
System
Figure 2.3 Squad Hierarchy
Squad
Training Squad
Competing Squad
J.E.D.I
Generalization is a form of association wherein one class shares the structure andor behavior of one or more classes. It defines a hierarchy of abstractions in which a
subclass inherits from one or more superclass. It is an is a kind of relationship. In Figure 2.3, the Squad class is the superclass of the Training Squad and Competing Squad
classes.
Inheritance is a mechanism by which more specific elements incorporate the structure and behavior of more general elements. A subclass inherits attributes, operations and
relationships from a superclass. Figure 2.3 is elaborated in Figure 2.4, all attributes and methods of the Squad superclass are inherited by the subclasses Training Squad and
Competing Squad.
Polymorphism is the ability to hide many different implementation behind a single interface. It allows the same message to be handled differently by different objects.
Consider the classes defined in Figure 2.5 which will be used to discuss polymorphism
1
. A superclass Person is modeled with two subclasses Student and Employee.
1 Examples are lifted from the Introduction to Programming Language JEDI Course Materials. Their use has prior approval from the authors.
Software Engineering 40
Figure 2.4 Elaborated Squad Hierarchy
Squad
Name MemberList
listMembers changeCoach
Training Squad Competing Squad
Figure 2.5 Polymorphism Sample
Person
Student Employee
J.E.D.I
In Java, consider the following code to implement the classes. public class Person
{ public String getName{
System.out.println“Person Name:” + name; return name;
} }
public class Student extends Person {
public String getName{ System.out.println“Student Name:” + name;
return name; }
} public class Employee extends Person
{ public String getName{
System.out.println“Employee Name:” + name; return name;
} }
Notice that both Student and Employee have different implementation of the getName method. Consider the following Java Main Method where ref is a reference to a class
Person. The first time that the ref.getName is invoked, it will execute the getName method of Student since ref references a studentObject. The second time that the
ref.getName is invoked, it will execute the getName method of Employee since ref references a employeeObject.
public static main String[] args {
Person ref;
Student studentObject = new Student;
Employee employeeObject = new Employee;
ref = studentObject; Person reference points to a Student object
String temp = ref.getName; getName of Student class is called
System.out.println temp ;
ref = employeeObject; Person reference points to an Employee object
String temp = ref.getName; getName of Employee class is called
System.out.println temp ;
}
Software Engineering 41
J.E.D.I
Aggregation is a special kind of association between objects. It models a whole-part relationship between an aggregate whole and its parts. Figure 2.6 shows an example
of an aggregation. Here, the team is composed of athletes.
Software Engineering 42
Figure 2.6 Team Aggregation
Team Athletes
J.E.D.I
2.2 Object-oriented Process Model