Dúvidas Abstract Factory

Asked

Viewed 56 times

0

I have this exercise to do but I’m not able to do the implementation

Using the Abstract Factory Standard, deploy Java clients from Process Manager and Memory Manager products to Linux, Mac, and Windows Operating Systems

So far all I’ve been able to do is this, I’m having a lot of doubts about how to finish this code :

public class FabricaWindows implements FabricadeGerenciador {

@Override
public void Gerenciadordeprocesso() {
    // TODO Auto-generated method stub

}

@Override
public void Gerenciadordememoria() {
    // TODO Auto-generated method stub

}



public class FabricaLinux implements FabricadeGerenciador {

@Override
public void Gerenciadordeprocesso() {
    // TODO Auto-generated method stub

}

@Override
public void Gerenciadordememoria() {
    // TODO Auto-generated method stub

}

}

public interface FabricadeGerenciador {
void Gerenciadordeprocesso();
void Gerenciadordememoria();
}




public interface Gerenciadordememoria {

}
public interface Gerenciadordeprocesso {

}

1 answer

0

The problem with its implementation is the return of methods. Abstractfactory is a pattern that serves precisely to create objects, in this case a family of objects. Therefore the methods void Gerenciadordeprocesso(); and void Gerenciadordememoria(); should have returns. The correct would be:

public interface FabricadeGerenciador {
    Gerenciadordememoria Gerenciadordeprocesso();
    Gerenciadordeprocesso Gerenciadordememoria();
}

With this, your code would be used as follows:

public static void main(String args[]) {
    FabricadeGerenciador fabrica = new FabricaWindows();
    Gerenciadordememoria gerenciadorMemoria = fabrica.Gerenciadordememoria();
    Gerenciadordeprocesso gerenciadorProcesso = fabrica.Gerenciadordeprocesso();
}

Tips:

  1. The methods of AbstractFactory are creation methods, so it would be interesting to use more appropriate names, for example, criarGerenciadorMemoria.
  2. Java method name must start with lowercase letter and follow the default Camel case nomenclature. That is, the name Gerenciadordeprocesso is out of standard. The correct would be gerenciadorDeProcesso.
  3. Class name and interface look like the Camel case, but the name should start with a capital letter. This pattern is called the pascal case. I mean, instead of Gerenciadordememoria, should be GerenciadorDeMemoria .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.