Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda