Doubts Abstract Factory

0

I have this exercise to do but I am not able to do the implementation

Using the Abstract Factory Pattern, deploy java Process Manager and Memory Manager products to Linux, Mac, and Windows operating systems

So far I've just been able to do this, I have a lot of doubts about how to end 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 {

}
    
asked by anonymous 09.11.2017 / 18:20

1 answer

0

The problem of its implementation is the returns of the methods. The AbstractFactory is a pattern that serves precisely to create objects, in this case a family of objects. Therefore, void Gerenciadordeprocesso(); and void Gerenciadordememoria(); methods 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:

  • The methods of AbstractFactory are methods of creation, so it would be interesting to use more appropriate names, for example, criarGerenciadorMemoria .
  • Method name in java should begin with a lowercase letter and should follow the camel case nomenclature pattern. That is, the name Gerenciadordeprocesso is out of the standard. The correct would be gerenciadorDeProcesso .
  • Class name and interface is similar to the camel case, except that the name must begin with a capital letter. This pattern is called a pascal case. That is, instead of Gerenciadordememoria , it should be GerenciadorDeMemoria .
  • 15.11.2017 / 03:32