-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
############################### | ||
# Facade # | ||
############################### | ||
|
||
|
||
|
||
|
||
|
||
##### Language - EN | ||
|
||
- We created a "Facade" to abstract complex implementations, the external system instead of knowing several classes of my system, | ||
he will only know the 'Facade', that way it will be easier to use. | ||
|
||
- A Facede serves as a single front for the services provided by one or more sub-systems, | ||
providing a simpler way for your consumption. | ||
|
||
##### Language - PT-BR | ||
|
||
- Nós criamos uma "Fachada" para abstrair implementações complexas, o sistema externa ao invés dele conhecer várias classes do meu sistema, | ||
ele irá conhecer apenas a 'Fachada', dessa forma facilita na utilização. | ||
|
||
- Uma Facede serve como uma frente única para os serviços disponibilizados por um ou mais sub-sistemas, | ||
provendo uma maneira mais simples para o seu consumo. | ||
|
||
|
||
|
||
############################### | ||
# Singletons # | ||
############################### | ||
|
||
|
||
|
||
|
||
|
||
##### Language - EN | ||
|
||
- It is the creation of a single instance for our entire application, it is as if it were a global object; | ||
|
||
- In my system, there will be a single instance of that object; | ||
|
||
|
||
##### Language - PT-BR | ||
|
||
- É a criação de uma única instancia para a nossa apliação toda, é como se fosse um objeto global; | ||
|
||
- No meu sistema, terá uma única instancia desse objeto; | ||
|
||
|
||
|
||
|
||
|
||
############################### | ||
# Weaknesses X Strong # | ||
############################### | ||
|
||
|
||
|
||
##### Language - EN | ||
|
||
- Singleton is the same problem that we have when using a global variable; | ||
|
||
- Facede we have a problem of our class being immense, with many things in it; | ||
|
||
|
||
##### Language - PT-BR | ||
|
||
- Singleton é o mesmo problema que temos quando usamos uma variavel global; | ||
|
||
- Facede temos um problema da nossa classe ficar imensa, com muitas coisas nela; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package facadesAndSingletons; | ||
|
||
import facadesAndSingletons.models.Client; | ||
import facadesAndSingletons.models.ClientDao; | ||
import facadesAndSingletons.models.Collection; | ||
import facadesAndSingletons.models.Invoice; | ||
|
||
//Code not be correct in classes, because this is a example | ||
public class CompanyFacede { | ||
|
||
protected CompanyFacede() { | ||
|
||
} | ||
|
||
public Client findClient(String cpf) { | ||
return new ClientDao().findByCpf(cpf); | ||
} | ||
|
||
public Invoice createInvoice(Client Client, double valor) { | ||
return new Invoice(Client, valor); | ||
} | ||
|
||
public Collection generateCollection(Invoice Invoice) { | ||
Collection cobranca = new Collection("Boleto", Invoice); | ||
cobranca.issueBill(); | ||
return cobranca; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package facadesAndSingletons; | ||
|
||
public class CompanyFacedeSingleton { | ||
|
||
private static CompanyFacede instance; | ||
|
||
public CompanyFacede getInstance() { | ||
if (instance == null) { | ||
instance = new CompanyFacede(); | ||
} | ||
return instance; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package facadesAndSingletons; | ||
|
||
import facadesAndSingletons.models.Client; | ||
import facadesAndSingletons.models.Invoice; | ||
|
||
public class FacedesAndSingletonsMain { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("--------------------------------------------- Begin Test Facedes and Singletons"); | ||
|
||
|
||
// Singleton | ||
CompanyFacede facade = new CompanyFacedeSingleton().getInstance(); | ||
|
||
//Facede | ||
facade.findClient("123456"); | ||
facade.createInvoice(new Client("MuPezzuol"), 50); | ||
facade.generateCollection(new Invoice(new Client("MuPezzuol"), 500)); | ||
|
||
// Facede + Singleton = Together this example | ||
|
||
|
||
System.out.println("--------------------------------------------- End Test Facedes and Singletons"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package facadesAndSingletons.models; | ||
|
||
public class Client { | ||
|
||
private String name; | ||
|
||
public Client() { | ||
super(); | ||
} | ||
|
||
public Client(String name) { | ||
super(); | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package facadesAndSingletons.models; | ||
|
||
public class ClientDao { | ||
|
||
public Client findByCpf(String cpf) { | ||
return new Client("Murillo Pezzuol"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package facadesAndSingletons.models; | ||
|
||
public class Collection { | ||
|
||
private String string; | ||
private Invoice invoice; | ||
|
||
public Collection(String string, Invoice invoice) { | ||
this.string = string; | ||
this.invoice = invoice; | ||
} | ||
|
||
public void issueBill() { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package facadesAndSingletons.models; | ||
|
||
public class Invoice { | ||
|
||
private Client client; | ||
private double valor; | ||
|
||
public Invoice(Client client, double valor) { | ||
this.client = client; | ||
this.valor = valor; | ||
} | ||
|
||
} |