Question

How would I go about implementing/converting this UML diagram to Java code? Do I have to use constructors?

Here is the diagram:

Diagram

Was it helpful?

Solution

Answer to your Question: No you dont have to use constructors, none of the classes shows one so youre fine with just the default constructors beeing generated while compiling.

Here is what you can do based on the assumption that this pictures information is stored in a understandable format (like for example extracted from IBMs Enterprise Architect).

1.) Learn Java so you can transform for example the box "CEO" into this:

public class CEO extends Employee{

 @Override
 public void printDetails(){}

 }

2.) Use a IDE/ Tool that can generate such class skeletons based on your diagramms information. ArgoUml, Enterrpise Architekt, BlueJ, IntelliJ and stuff, just google for "java uml to code"

3.) Write a Tool that parses UML pictures metadata and generates the appropriate code.

In your case you probably want to go for 2.) and then hire a application developper to fill the generated skeletons with functionality.

Edit: As other comments suggested there is a problem with your diagramm. Before programms like in 2.) above can parse the information to generate class skeletons it must be understandable what the relations (arrows) in your diagramm express. Look at the relation between for example Office and Departement. I as a human can interpret this as "yeah that arrows probably do tell that a office extends from a Departement rather than telling me that a Departement has a reference to a Office and vice a verse". But that a tool can make this decission it must be clear what of both is meant. Usualy this arrows would suggest both classes holding a references to the other one and you probably rather want a single arrow pointing from Office to departement that has a Label "extends" or "implements" attached.

OTHER TIPS

First of all, you will have to understand what each notation in UML means based on which you can convert those to java classes. Below is a nice article that attempts to explain.

http://java.dzone.com/articles/uml2-class-diagram-java

Use UML tool ArgoUML. It is based on java. ArgoUML is the leading open source UML modeling tool and includes support for all standard UML 1.4 diagrams. Default constructors is a good practice as in some case like singleton pattern you have a private constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top