Design Patterns SW Quality - English Version
Design Patterns SW Quality - English Version
INTRODUCTION
DESIGN PATTERNS
classPersonType
NATURAL=1;
JURIDICAL=2;
end
classPerson
@personName;
@personType;
@messageList;
definitialize(personType)
@personType=personType;
end
end
classMessage
@menssageData;
end
classPersonService
@person;
definitialize(person)
@person=person;
end
defsendMessage(mess)
# message sending implementation
end
end
Tabela 1. Source Code for an Anemic Domain
if(actualVehicle.isMonitored()) {
for(TrackingSystemservice:
actualVehicle.getAvailableServices()) {
switch(service) {
case OUT_OF_ROUTE:
Alert serviceAlert =
newAlertOutOfRoute();
executionAlert.put(atualVehicle,
serviceAlert);
break;
case NOT_ALLOWED_BREAK:
Alerta serviceAlert =
newAlertNotAllowedBreak();
executionAlert.put(actualVehicle,
serviceAlert);
break;
default:
break;
}
}
}
Table 2. Source code used to program to the interface
The code above shows that beyond creating the necessary Alerts
for the vehicles with available services, it returns Alerts contained in one
List to be afterward executed by another thread. Consider the situation
that many parts of the system make use of the Alerts, and despite of it
looks not so probably in the beginning of the project, one future
requirement may need the same code impacting in a negative
duplicated code.
4. SOLUTION PROPOSAL TO THE FOLLOWING DESIGN PROBLEMS
The image bellow shows one service object that applies the
singleton pattern:
The C# code bellow shows the coded example for this problem:
Public classConnectionService{
privateConnectionService instance;
privateDbConnection connection;
privateConnectionService() {
this.InitDB();
if(instance == null)
{
instance = newConnectionService();
}
else
{
if(instance.conexao.ConnectionState
== ConnectionState.Closed)
{
InitDB();
}
}
catch(Exception e) {
thrownewException(e.ToString());
}
returninstance;
}
privatevoidInitDB() {
// establish database connection
}
}
Table 3. Source code with the singleton implementation
privateDbConnection connection;
publicList<Person>RecuperaListaPessoas() {
List<Person>clRetorno = newList<NaturalPerson>();
connection = ConnectionService.Instance;
DbCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM Person";
while(reader.Read())
{
Person p = newNaturalPerson();
p.setId(rs.getInt("id"));
p.setName(rs.getString("name"));
clRetorno.add(p);
returnclRetorno;
The code bellow shows the use of the unique connection and
centralized when necessary, the benefit and facility of use, brings
benefits of reuse and network and system performance.
The two teams will help to achieve a quality domain model with
many meetings, informal conversations and knowledge transfer, in both
sides. But it is not any conversation that is useful. The useful
conversation is the one that the result becomes integrated to the code,
with no intermediates. Terms used by the teams has to be widely
accepted, used and understood as the language the two teams has to be
the same.
To define a common language to the both teams, Evans defined as
the ubiquitous language the terms that has to be applied in classes,
operations, attributes and all the software artifacts. This language
includes terms to discuss rules that have been defined in the domain
model.
publicAlertacreateAlert(TrackingServiceservice) {
switch(service) {
caseOUT_OF_ROUTE:
returnAlert = newAlertOutOfRoute();
break;
caseNOT_ALLOWED_BREAK:
returnAlert = newAlertNotAllowedBreak();
break;
default:
break;
returnreturnAlert;
}
5. CONCLUSION
REFERENCES
[1] PRESSMAN, R. S. Software Engineering: a practitioner's approach. [9] GAMMA, Erich et. al. Design Patterns: Elements of Reusable-
(2004). pp. 96-97. Oriented Software. (1994). pp. 130.
[2] PRESSMAN, R. S. Software Engineering: a practitioner's approach. [10] GAMMA, Erich et. al. Design Patterns: Elements of Reusable-
(2004). pp. 97. Oriented Software. (1994). pp. 130.
[3] GAMMA, Erich et. al. Design Patterns: Elements of Reusable- [11] EVANS, E. Domain-driven design: tackling complexity in the heart
Oriented Software. (1994). pp. 11. of software. (2004). pp. 3.
[4] GAMMA, Erich et. al. Design Patterns: Elements of Reusable- [12] EVANS, E. Domain-driven design: tackling complexity in the heart
Oriented Software. (1994). pp. 12. of software. (2004). pp. 3.
[5] FOWLER, M. Anemic Domain Model. (2003) [13] EVANS, E. Domain-driven design: tackling complexity in the heart
of software. (2004). pp. 24.
[6] WEISFIELD, M. A. The object-oriented thought process. (2004)
[14] FREEMAN, E; Heard First: Design Patterns. (2004) pp. 111.
[7] KHOR, K-K. IBM Smalltalk Tutorial. (1995)
[15] GAMMA, Erich et. al. Design Patterns: Elements of Reusable-
[8] MAIORIELLO, J. Applying Design Patterns to Solve Design Issues Oriented Software. (1994). pp. 96.
(2003)