Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

330
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda