Skip to content

Commit

Permalink
Add Facede and Singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
mupezzuol committed Mar 26, 2020
1 parent 61f3dc0 commit 4ae38a9
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Project that implements some design patterns using Java 13.
- Interpreter
- Visitor
- Bridges and Adapters
- Command
- Command
- Facades and Singletons
76 changes: 76 additions & 0 deletions src/facadesAndSingletons/Annotation.txt
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;







30 changes: 30 additions & 0 deletions src/facadesAndSingletons/CompanyFacede.java
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;
}


}
14 changes: 14 additions & 0 deletions src/facadesAndSingletons/CompanyFacedeSingleton.java
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;
}

}
26 changes: 26 additions & 0 deletions src/facadesAndSingletons/FacedesAndSingletonsMain.java
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");
}

}
24 changes: 24 additions & 0 deletions src/facadesAndSingletons/models/Client.java
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;
}

}
9 changes: 9 additions & 0 deletions src/facadesAndSingletons/models/ClientDao.java
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");
}

}
17 changes: 17 additions & 0 deletions src/facadesAndSingletons/models/Collection.java
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
}

}
13 changes: 13 additions & 0 deletions src/facadesAndSingletons/models/Invoice.java
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;
}

}

0 comments on commit 4ae38a9

Please sign in to comment.