• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer
  • Core Java
  • Design Patterns
  • JSP
  • Servlets
  • Building Tools
  • jQuery
  • Spring
  • Hibernate
  • Mongo DB
  • More
    • HTML
    • SCJP
    • AJAX
    • UML
    • Struts
    • J2EE
    • Testing
    • Angular JS

J2EE Reference

  • Home
  • About Us
    • Java Learning Centers
  • Contact Us

UML

Aggregation and Composition

June 22, 2012 By j2eereference Leave a Comment

Aggregation

Aggregation is a relationship between two classes . That is ,  an object “has-a”  relation with another object.

Lets take an example of the relation between a Person and Address. There is an aggregation relationship between person and Address. Here we can say that a Person class has address object. Person does not manage the lifetime of Address. If Person is destroyed, the Address still exists.

How to represent Aggregation

Aggregation is represented with an unfilled diamond

Address Person

 

Below code will help you to understand java implementation of Aggregation.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.j2eereference.aggregation;
 
public class Person{
private String personName;
private int age;
private Address address;
 
public Person(String personName,int age, Address address) {
this.personName= personName;
this.age= age;
this.address= address;
}
 
public String getPersonName() {
return personName;
}
 
public int getAge() {
return age;
}
 
public Engine getAddress() {
return address;
}
}

Now we can create the Address class as below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.j2eereference.aggregation;
 
public class Address{
    private String city;
    private int zipCode;
 
    public Address(String city, int zipCode) {
        this.city= city;
        this.zipCode= zipCode;
    }
 
    public String getCity() {
        return city;
    }
 
    public int getZipCode() {
        return zipCode;
    }
}

Here you can notice that

  • The address object is created outside and is passed as argument to Person constructor.
  • When this person object is destroyed, the address will be still available.

Composition

We can say that composition gives us a ‘part-of‘ relationship.

How to represent Composition

Composition is represented with a filled diamond.

Engine  CAR

When an object contains the other object  and if the contained object cannot exist without the existence of container object, then it is called composition. Lets take an  example of Car – Engine and see how can we achieve this composite  relation using java code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.j2eereference.composition;
public class Car {
private String make;
private int year;
private Engine engine;
 
public Car(String make, int year, int engineCapacity, int engineNumber) {
this.make=make;
this.year=year;
engine = new Engine(engineCapacity, engineNumber);
}
 
public String getMake() {
return make;
}
 
public int getYear() {
return year;
}
 
public int getEngineNumber() {
return engine.getEngineNumber();
}
 
public int getEngineCapacity() {
return engine.getEngineCapacity();
}
}

Here you can notice the below points

  • We created  the engine using parameters passed in Car constructor
  • Only the Car instance has access to the engine instance
  • When Car instance is destroyed, the engine instance also get destroyed

Filed Under: UML

UML – Object Diagram

May 27, 2011 By j2eereference Leave a Comment

In any application Classes are not directly used. But instance / Object of the classes are used for executing the business logic. Representing the relation between these objects at any point of time is called Object diagram.
With the help of an object diagram we can understand how the classes are interact at run time.

Object diagram concentrates on some particular objects and attributes and the links between the objects and it tells how a system evolves over time. Object diagram is used to show a particular model of system which we are interested

Elements of an Object diagram

As object diagram is the instance of classes, it consists of same element as the class diagram.

Example:  Let us consider the example of Course and Students class.  The class diagram for this can be as below.

Here we can notice that a course has many Students, We can represent the same at the run time using an Object diagram as below.

Filed Under: UML

UML- Use Case Diagram

May 24, 2011 By j2eereference 1 Comment

1. Use Case Diagram describes interaction between user and the system.

2. Use Case Diagram doesn’t tell detailed information about individual feature of the system, it is used to describe the complete functionality of the system.

3. Use Case Diagram is suited to describe high level functionality of the system, it is not recommended to use where we have to capture the entire flow of the system like number of hits to a particular module or exceptions etc.

4. Use Case Diagram has four major elements

• Actors:  A role that a user plays with respect to the system,including human users and other systems. e.g.,inanimate physical objects (e.g. robot); an external system that needs some information from the current system.

• Use Case: A set of scenarios that describing an interaction  between a user and a system, including alternatives.

• System boundary :A rectangle diagram representing the boundary between the actors and the system.

• Relationships: The lines between the elements

5. How to identify actors in Use Case Diagram?

Elements whose behavior appears in actors actions column are actors, it may be humans or system interacting with other system example: cronjob interacting with a database for updating user information here cronjob is a process which is actor in Use Case Diagram because it interacts with the other system which is database here other example for humans online banking here humans are actors because they are interacting with the banking system to get there work done by sending a request to the system.

6. how to identify systems in Use Case Diagram?

Elements whose behavior appears in System responses column are components in the system, system box contains use cases one for each service that the system provide to the actors, any internal behavior of the system that the other parts of the system uses should not appear in system box

Filed Under: UML

UML – Class Diagram

January 31, 2011 By j2eereference 2 Comments

Classes are the most important building blocks of UML. In fact classes are at the core of  any object oriented system. . A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics. Now let us see how these are modeled in UML.

.         A  class is represented in UML by a rectangle with three components

Class : The first compartment in the UML diagram contains the Class name, Which UML recommends is centered and in bold.

Attributes : UML recommends the name of attribute are left justified and in plain type

Operations () : UML recommends the name of operations  are left justified and in plain type

·         Every class must have a name that distinguishes it from other classes. The class name is  a textual string written with the first letter in upper case.

·         A class may be drawn showing only its name.

·         Abstract class names are shown in italics or by using braces.

 When representing a class you can choose to show

Attributes , but not operations

Operations but not attributes

Attributes and operations 

Or if you don’t want to show any of a class’s attributes or operations , You can simply represent it with a plain rectangle 

The following is standard UML convention for naming classes

Class name should be

Singular nouns

Start with an uppercase letter

Although not a UML recommendation, if you need give a class name with more than one  word you should capitalize the initial letter of each word.

 There is no strict UML convention for naming attributes and operations. But in common practice , the initial letter of the attributes and operations should not be capitalized . But initial letter of each word should be capitalized.

Example :

Bank Account

owner : String
balance:float=  5000
deposite  ()

withdrawl ()

 

Class diagrams also display relationships such as containment, inheritance, associations and others.

Filed Under: UML

An Overview of UML

January 31, 2011 By j2eereference 1 Comment

What is UML?   

Unified Modeling Language (UML) is a general-purpose visual modeling language that is used to visualise, specify, construct and document the artifacts of a software system. It is a language in the sense that it has a standard vocabulary and rules. The vocabulary and rules of the UML tell us how to create and read well-formed models. But it does not tell us what models to create and when to create them. It has static, dynamic, environmental and organisational parts to help capture the differing aspects of a problem. At the same time it must be remembered that UML is not a programming language. Therefore, it can not be used for writing codes. It is most useful for modeling discrete systems like software, firmware etc. UML specification does not define a standard process, but is intended to be useful with an iterative development process. It is intended to support most existing object oriented development processes. The UML is a language for:

•      Visualising.  Firstly, The  UML is more than just a bunch of graphical symbols. The UML notations are supported by well defined semantics. Using UML, one developer can develop a model, which can be easily interpreted by another. Secondly, there are a number of things about software which can not be easily comprehended. For example, looking at a code one may infer the classes by looking at the hierarachy, but how they relate to each other and what conditions apply to their operations can not be easily grasped. UML’s graphical notations help visualising these details. Finally, a developer who wrote the code does not write down the model, the information would be lost forever.

•      Specifying.  UML addresses all important analysis, design, and implementation decisions that must be made in developing and deploying software systems. 

•      Constructing.  UML  is not a visual programming language. But its models can be directly connected to a variety of programming languages. This means that UML models can be mapped to programming languages like C++, Java, Visual Basic etc., or even to RDBMS tables.

•      Documenting.   The very approach of developing models using UML is conducive to capturing all analysis, design, implementation, packaging, and deployment issues of a problem in well structured and defined models. By providing additional flexibility to its language, UML helps in expressing requirements for tests as well.

Building Blocks of UML

The vocabulary of UML encompasses three kinds of building blocks: 
Things. 

The ‘things’ are the nouns in a model. UML identifies four kinds of ‘things’. These are:

  • Structural things (seven).
  • Behavioural things (two).
  • Grouping things (one).
  • Annotational things (one).  

Relationships. 

There are four kinds of ‘relationships’ in the UML. These are:

  • Dependency.
  • Association.
  • Generalisation.
  • Realisation.

 Diagrams. 

A diagram is a graphical representation of a set of things and the relationships that exist between them. Diagrams are drawn to visualise the system from different perspectives, as mentioned earlier. There  are nine diagrams in the UML. These are: 

  • Class diagram.
  • Object diagram.
  • Use case diagram.
  • Sequence diagram.
  • Collaboration diagram.
  • Statechart diagram.
  • Activity diagram.
  • Component diagram.
  • Deployment diagram.

Filed Under: UML

Primary Sidebar

FOLLOW US ONLINE

  • View J2eereference-166104970118637’s profile on Facebook
  • View j2eereference’s profile on Twitter
  • View j2eereference’s profile on LinkedIn

Subscribe by email

Recent posts

  • Java Buzzwords
  • Anonymous Inner Class in Java
  • Network Programming – java.net Package
  • Java Regular Expressions
  • Method Local Inner Class in Java
  • URL Processing in Java
  • Iterator Design Pattern Implementation using Java
  • Strategy Design Pattern Implementation using Java
  • Decorator Design Pattern
  • Adapter Design Pattern Implementation using Java
  • JSF Composite Components
  • JSF UI Components
  • What is JavaServer Faces (JSF)?
  • GOF Design Patterns
  • History and Need for Design Patterns

Footer

Core Java
Design Patterns
JSP
Servlets
HTML
Building Tools
AJAX
SCJP
jQuery
Testing
Spring
UML
Struts
Java Centers
Java Training
Home
About Us
Contact Us
Copyright © j2eereference.com. All right reserved.