-
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
4 changed files
with
108 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,40 @@ | ||
############################### | ||
# Factory # | ||
############################### | ||
|
||
|
||
|
||
|
||
|
||
##### Language - EN | ||
|
||
- We generally use a builder when we need to pass various information to the logic that assembles the object. | ||
|
||
|
||
BUILDER X FACTORY | ||
-> They are called creation patterns, which create objects; | ||
-> Builder is a creator of more complex objects, which can be different according to calls, where we can have several types of objects. | ||
-> Factory is something we can create but it will hardly be changed, and if it is, everyone who called it will be changed, therefore, | ||
the creation follows the same line of the object, different from the Builder that the creation can be specified for each passed argument. | ||
|
||
+ We generally use a builder when we need to pass various information to the logic that assembles the object. | ||
+ We use a factory when we have to isolate the process of creating an object in one place. | ||
This factory can figure out how to create the object inside itself, but it usually doesn't need a lot of information to create the object. | ||
|
||
|
||
|
||
|
||
##### Language - PT-BR | ||
|
||
- Geralmente usamos um builder quando precisamos passar diversas informações para a lógica que monta o objeto. | ||
|
||
|
||
BUILDER X FACTORY | ||
-> São chamados de padrões criacionais, que realizam criação de objetos; | ||
-> O Builder é um criador de objetos mais complexos, que podem ser diferentes de acordo com as chamadas, onde podemos ter várias tipos de objetos. | ||
-> O Factory é algo que nós podemos criar mas dificilmente será alterado, e caso seja, todos aqueles que fizeram chamada dele serão alterados, portanto, | ||
a criação segue a mesma linha do objeto, diferente do Builder que a criação pode ser especifica para cada argumento passado. | ||
|
||
+ Geralmente usamos um builder quando precisamos passar diversas informações para a lógica que monta o objeto. | ||
+ Usamos uma fábrica quando temos que isolar o processo de criação de um objeto em um único lugar. | ||
Essa fábrica pode descobrir como criar o objeto dentro dela própria, mas geralmente ela não precisa de muitas informações para criar o objeto. |
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,25 @@ | ||
package factory; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
|
||
public class ConnectionFactory { | ||
|
||
public Connection getConnection() { | ||
try { | ||
// Using VAR | ||
var server = "localhost"; | ||
var banco = "dbtest"; | ||
var user = "root"; | ||
var pass = "1234"; | ||
|
||
Connection con = DriverManager.getConnection("jdbc:postgres://"+server+"/"+banco, user, pass); | ||
|
||
return con; | ||
|
||
} catch (Exception e) { | ||
throw new RuntimeException("Exception: " + e); | ||
} | ||
} | ||
|
||
} |
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,21 @@ | ||
package factory; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
public class FactoryMain { | ||
|
||
public static void main(String[] args) throws SQLException { | ||
System.out.println("--------------------------------------------- Begin Test Factory"); | ||
|
||
// Call method Factory for create a Connection | ||
Connection con = new ConnectionFactory().getConnection(); | ||
|
||
PreparedStatement ps = con.prepareStatement("select * from table;"); | ||
|
||
|
||
System.out.println("--------------------------------------------- End Test Factory"); | ||
} | ||
|
||
} |