You are on page 1of 4

Project Complition

1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

Composition: primitive data type Library of data type: already exist but only show in the repository when needed Hide repository Add new category interface Comments a default class description Enforce Description Display the aggregation in the reuse interface Extract class with its composition Extraction progress bar If the code does not contain class then prompt message "Sorry!!, We are unable to find

available class to extract"

Java Object Composition Syntax for Reuse (http://www.java-forums.org/blogs/java-object/634-compositionsyntax-reuse.html) One of the best features of Java is code reuse. But like any tool, it needs to be used effectively. Most programmers might be lead to think that when I talk of reuse only relates to extending a class. Now there is nothing wrong with reusing a class by extending it or using it directly. This type of reuse is using the class without the risk changing the existing code. First we can create objects of the existing class inside the new class. We call this composition. It is a new class composed of objects of existing classes. What youre doing is reusing the functionality not its form. The second approach is to create a new type of class from an existing class. You take the form of an existing class and add code to it without making changes to the existing class (inheritance).

An example of composition below.

Java Code:

public class Transport { public void move(){ }

public void start(){ }

public void stop(){ }

public class Airplane {

private Transport transport;

public Airplane() { transport = new Transport(); }

Here is the same example shown as inheritance

public class Airplane extends Transport {

} Aggregation (http://java.about.com/od/a/g/aggregation.htm) Definition:

Aggregation is a relationship between two classes that is best described as a "has-a" and "whole/part" relationship. It is a more specialized version of the association relationship. The aggregate class contains a reference to another class and is said to have ownership of that class. Each class referenced is considered to be part-of the aggregate class Ownership occurs because there can be no cyclic references in an aggregation relationship. If Class A contains a reference to Class B and Class B contains a reference to Class A then no clear ownership can be determined and the relationship is simply one of association. For example, imagine a Student class that stores information about individual students at a school. Now let's say there is a Subject class that holds the details about a particular subject (e.g., history, geography). If the Student class is defined to contain a Subject object then it can be said that the Student object has-a Subject object. The Subject object also makes uppart-of the Student object, after all there is no student without a subject to study. The Student object is therefore the owner of the Subject object. Examples: There is an aggregation relationship between Student class and the Subject class: public class Subject { private String name; public void setName(String name) { this.name = name; } public String getName() {

return name; } } public class Student { private Subject[] studyAreas = new Subject[10]; //the rest of the Student class }

You might also like