UML in java

Hi,

I am reading below link

https://weblogs.java.net/blog/potty/archive/2014/01/22/introduction-class-diagrams

Dependency

Declares that a class needs to know about another class to use objects of that class. Its representation is a dashed arrow.

Association

Means that a class will contain a reference to an object of another class in the form of an attribute. Its representation is the straight line, the association name and the attributes (or Class) involved. An example is "Student --take--> Course".

Aggregation

Indicate that a class owns but may share objects of another class. Its representation is by an empty diamond, a straight line, the aggregation name and the attribute shared. An example is "Person ?---- Address".

Composition

It work similar as Aggregation but in a stronger way. Its representation is by a filled diamond, a straight line, the aggregation name and the attribute shared. An example is "Person -----? Name".

Generalization

It is also called Inheritance. Used to describe a class that is a type of another class. Its representation is by an empty triangle and a straight line. An example is "Mammal -----? Dog".

I am not completely clear with above topics. Is there is any good simple examples explaining each.
Please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim CakalicSenior Developer/ArchitectCommented:
gudii9Author Commented:
Dependency
Association
Generalization
Extensibility

any code examples with real classes, objects showing these concepts?

Please advise
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

David L. HansenCEOCommented:
Before getting into any code, do you feel comfortable with the concepts? For example: generalization is the term used when one class inherits from another class.

Example of Generalization: Class "Dog" inherits from Class "Mammal". Note, Dog can NEVER be created or EVER exist without having ALL of the properties and methods which belong to "Mammal". These are baked PERMANENTLY into the "Dog" class because it inherits "Mammal".

Example  of Dependency: Class "Dog" may depend on a "Hair" Class. So, when you instantiate a dog from its class you decide that the Hair type should be specified at that time as an input parameter. Note that "Hair" is a separate class and must be instantiated separately and then passed in during the creation of the dog. However, Hair (at least in my example) isn't part of what a dog IS (meaning you could just specify "none", or "hairless", for hair and your dog object will still be created successfully).  

I can continue on with more examples or dive into code at this point. If you feel you understand all five concepts then I don't mind doing that.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amitkumar PSr. ConsultantCommented:
Please go thru class diagrams explained in uml-diagrams.
gudii9Author Commented:
http://www.umlet.com/

i will get it as eclipse plug in.
gudii9Author Commented:
I can continue on with more examples or dive into code at this point. If you feel you understand all five concepts then I don't mind doing that.

generalization and dependency i got it. Please advise with simple code examples as well all the five.
David L. HansenCEOCommented:
There are many code examples on the internet on these topics. Have you looked at these? If you have, and still have questions, I wonder if discussing these topics wouldn't be more beneficial. I doubt that I can come up with any code that will shed more light on the subject than the code samples that are already out there.

http://question.ikende.com/question/2D31373530373736303833

http://www.c-sharpcorner.com/UploadFile/b1df45/dependency-generalization-association-aggregation-compos/
gudii9Author Commented:
Class Client
{

    BankAccount acc = new BankAccount();

    public void addMoneyToBankAccount(decimal amount)
    {         
        acc.AddMoney(amount);
    }

    public decimal CheckBalance()
    {
        return acc.CheckAccountBalance();
    }

}

Open in new window

above is composition since client contains BankAccount?

where as below is aggregation since client has only reference for BankAccount ?

Class Client
{

    BankAccount acc;
Class Client
{

    BankAccount acc;

    public Client(BankAccount p_acc)
    {
      acc=p_acc;
    }

    public void addMoneyToBankAccount(decimal amount)
    {         
        acc.AddMoney(amount);
    }

    public decimal CheckBalance()
    {
        return acc.CheckAccountBalance();
    }

}

Open in new window

David L. HansenCEOCommented:
Yes, when Client receives Bankaccount as a passed in (by reference) object then it is aggregation (if client dies, Bankaccount continues to survive).

With composite, the Bankaccount is a part of Client and dies when the Client dies.

You seem to be on the right track. Sometimes it's just a judgment call as to which relationship is best to use. That's where the art comes in (it's not a science) but this kind of logic will help you look at the objects, how they relate, under the given situation and help you creating a good design.
gudii9Author Commented:
Class Client
{

    BankAccount acc = new BankAccount();

in above example of composition we still need a BankAccount class somewhere write like

Public Class BankAccount {

int acctNbr;
int acctName;
getAcctNbr(){}
setAcctNbr(){}
//getter setter for acctName
So BankAccount object dies but the class which is blue print of object remains somewhere which we do not care right?
gudii9Author Commented:
Class Client
{

    BankAccount acc;

    public Client(BankAccount p_acc)
    {
      acc=p_acc;
    }

in case of aggregation we are simply creating instance of BankAccount  and equating that with whatever is passed withing Client() method right like

acc=p_acc;
gudii9Author Commented:
That's where the art comes in (it's not a science) but this kind of logic will help you look at the objects, how they relate, under the given situation and help you creating a good design.

any good links, reference articles, books on this topic?please advise
David L. HansenCEOCommented:
I think you've got it. Life cycle is important when judging between aggregation and composition. I like this  one - Two cowboys exist, one with a real mustache and the other with a fake one. They shoot each other and both die. One mustache dies and the other one is perfectly fine. The fake one is an aggregate and the real one was composition.

As to good books on the subject, I like "Object Oriented Analysis and Design" it's in the "Head First" series of books (ISBN: 9780596008673). Also, I've got an OOP article here that references a couple nice websites on the subject.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.