Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

336
Views
UML Object Diagram: Parent or Child

Let's say I have the following class :

public class ParentClass{}

And one of its children classes is :

public class ChildClass extends ParentClass{}

Let's consider another class :

public class Foo{
    
    private ParentClass field;
    
    public Foo(){
        
        field = new ChildClass();
        
    }
    
    public static void main(String[] args){
        
        Foo foo = new Foo();
        
    }
    
}

When drawing the Object Diagram of foo I don't know if I have to write ChildClass :

enter image description here

Or ParentClass :

enter image description here

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In your program field is an instance of ChildClass, the goal of the object diagram is to show instances with their effective type (and their attributes value if they have) => the right diagram to use is

enter image description here


[edit from remarks to my answer]

It is also legal to use the second diagram, but that one hide the fact the instance is for sure an instance of ChildClass, so better to use the first diagram to indicate that.

I forgot to mention in both your diagrams the line between the two instances does not correspond to the alone association between them, a right way to do for the first diagram is :

enter image description here

considering your instance of Foo is saved through a variable named foo it seems reasonable to name foo your instance of Foo

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!