DPAT
DPAT
CT070-3-3-DPAT (052024-MER)
Design Patterns
APD3F2405SE
In the rapidly evolving landscape of software development, efficiency stands as a very important
objective. Achieving optimal performance, scalability, and maintainability in software systems
requires a careful balance of resource utilization, responsiveness, and robustness. Design patterns
offer a structured approach to solving common software design challenges, thereby playing a
crucial role in enhancing software efficiency. This project explores the impact of design patterns
on software efficiency, focusing on their application during the software development process.
Through a comprehensive literature review and a practical case study on a Car Rental
Management System, the project demonstrates how specific design patterns, such as the State
and Facade patterns, can significantly improve system performance by streamlining code
structure, reducing redundancy, and optimizing resource usage. The analysis provides insights
into how design patterns contribute to the development of efficient, maintainable, and scalable
software solutions, making them indispensable tools in modern software engineering.
Table of Content
CT070-3-3-DPAT (052024-MER)..................................................................................................1
Abstract............................................................................................................................................1
Table of Content..............................................................................................................................1
Introduction......................................................................................................................................2
Literature Review............................................................................................................................3
Understanding Software Efficiency.............................................................................................3
The Importance of Efficiency in Software Systems....................................................................4
Techniques for Measuring Efficiency in Software......................................................................5
Impact of Design Patterns on Software Efficiency and Performance.........................................6
Design..............................................................................................................................................7
Scenario.......................................................................................................................................7
1|Page
Use case Diagram........................................................................................................................8
Simple Solution...............................................................................................................................8
Class Diagram..............................................................................................................................9
Java implementation (without using design patterns)...............................................................10
Refined Solution............................................................................................................................16
Problems with the Basic Solution..............................................................................................16
Chosen Design Patterns.............................................................................................................18
Class Diagram............................................................................................................................18
Java implementation (using design patterns).............................................................................20
References......................................................................................................................................26
Introduction
The significance of software efficiency is increasing along with the complexity and size of
software systems. A system that is responsive, scalable, and maintainable over time is ensured by
software that is efficient in meeting functional requirements while consuming the fewest
resources possible. Due to their ability to provide dependable fixes for frequent design issues that
might impede productivity, design patterns have become indispensable resources for software
developers.
Design patterns encapsulates some of the best practices in software design and provides
templates that guide the development process in such a way that promotes code reuse,
modularity and clarity. By addressing common structural and behavioral issues, design pattern
help developers avoid inefficient code practices such as excessive coupling, redundancy and
unnecessary complexity, which in turn leads to more efficient software which is easy to maintain
and scalable.
This project delves into the role of design patterns in enhancing software efficiency, with a
particular focus on their application during the refactoring of existing systems. Refactoring is the
2|Page
process of restructuring existing code without changing its external behavior, aimed at improving
the internal structure of the software. Design patterns are often employed during refactoring to
address inefficiencies that have emerged as a result of ad-hoc development or evolving
requirements.
The study begins with a detailed literature review that explores design patterns and their
relevance to software efficiency. It then presents a case study on the refactoring of a Car Rental
Management System, where specific design patterns, including the State and Facade patterns, are
applied to improve the system's performance and maintainability. The case study showcases the
practical benefits of these patterns, demonstrating how they can simplify complex code, reduce
processing overhead, and enhance the overall efficiency of the software.
The goal of this project is to offer insightful information about how to use design patterns to
develop software systems that are efficient in the face of change. The results highlight how
crucial it is to include design patterns in the software development lifecycle, especially when
refactoring is at its most crucial stage and efficiency advantages might be realized.
Literature Review
Software efficiency refers to the ability of a software application to effectively utilize the
available resources while delivering the necessary performance expected. A software that is
efficient minimizes resource consumption such as memory, processing power and storage used
while maximizing the output, which is an aspect of resource utilization which is imperative to
ensuring that the software runs smoothly as well as meets the performance expectations without
placing heavy burdens on the system’s resources (Tigulla & Kalidasu, 2015).
Another crucial component to software efficiency is time behavior, which includes the sub-
attributes such as response time, throughput, which is the amount of data sent and received
during a set time-frame, and the turnaround time. Time behavior is particularly crucial in real-
3|Page
time applications where delays in response time can lead to significant issues, affecting both
usability and functionality. While throughput refers to the amount of work done by the software
in a set time period, turnaround time instead accounts for the total time taken for a specific task
to be completed from start to end (Tigulla & Kalidasu, 2015). In environments where multiple
users are accessing the software simultaneously, throughput becomes a critical measure of how
well the software can scale to meet demand.
Adhering to quality standards is a very important for software developers in order to ensure that
the software meets the efficiency requirements, as these standards are what influence the overall
quality of the final software product. Developers must place focus on efficiency during the
development phase to successfully produce high-quality results (Tigulla & Kalidasu, 2015).
Efficiency can be measured by the use of various metrics as well as attributes, with the research
identifying three primary efficiency attributes which were suitable for web browsers, which were
response time, memory utilization and throughput, and the paper indicates that these attributes
can be further analyzed in order to gain a more detailed understanding of the efficiency of the
software system (Tigulla & Kalidasu, 2015).
The quality attribute efficiency of a software system is a critical quality attribute which has a
direct effect on both the development process as well as the end-user experience. Efficient
software optimizes its resource utilization which leads to ensuring that the system uses the CPU
(processing power), memory and bandwidth effectively and efficiently. Optimization in such a
way is especially imperative in an environment with resource-constraints, where it is paramount
to maintain a high level of performance while at the same time reducing operational costs
(Barbacci et al., 1995). Furthermore, efficiency also contributes towards user satisfaction, as
faster response times in addition to smoother interactions allow the user to use the system and
achieve their goals in less time along with minimal effort. This increase in customer satisfaction
is crucial for retaining the customer and improving the overall user experience which is a key
factor while within the competitive software market (Barbacci et al., 1995).
4|Page
Moreover, efficient software systems succeed in lowering developmental and operational costs
for organizations due to the reduced requirements of computational power as well as supporting
more users simultaneously, which in turn leads to increased scalability and reduced infrastructure
expenses (Barbacci et al., 1995). Through a long-term perspective, efficiency provides numerous
benefits over time such as easier maintainability and reusability of software components, which
ultimately saves time and resources which could in turn be used for future projects (Barbacci et
al., 1995). The efficiency of a software product can serve as the key differentiating factor within
a competitive market, making it more attractive to more users and thereby increasing profitability
(Barbacci et al., 1995). Optimized software can also lead to reduced latency, improving the speed
and reliability of interactions, which is essential for applications requiring real-time data
processing. Lastly, efficiency is a quality attribute closely related to the others such as reliability
and maintainability which is proved by the fact that optimized software tends to have increased
levels of reliability in addition to being easier to maintain, both of which further the contribution
to the overall quality of the software (Barbacci et al., 1995).
Measuring the efficiency of software applications, especially in the context of design patterns
and refactoring, involves various dynamic and static techniques. Dynamic Performance
Efficiency Measurement is a pivotal approach that assesses software performance in real-time
during execution, this helps the developers identify bottlenecks in real-time and implement
immediate improvements wherever necessary. This method is particularly useful for evaluating
how well the system responds to user actions and manages different workloads. By comparing
the performance of legacy systems with those that have been refactored, developers can identify
improvements and gain insights into how efficiency has been enhanced (Langsari et al., 2018).
Real-time measurement tools provide invaluable insights into how different modules of the
software interact under varying workloads, helping developers optimize system performance.
An other important technique is the Response Time Measurement, which involves calculating
the average time taken by the software system to respond to user requests, a metric which is
essential for understanding how efficient an application is in handling user interaction. By
continually monitoring response times, developers can proactively address performance issues
5|Page
before they impact the user experience. Throughput measurement is a technique which involves
assessing the number of transactions or operations that a system can process within a specific
time frame, which is another example of a measurement technique which acts as an effective
indicator of software efficiency. This measurement is often analyzed along with response time to
provide a comprehensive view of performance efficiency (Langsari et al., 2018). The
combination of Throughput Measurement and Response Time Measurement offers a holistic
view of a system's performance under load, enabling more informed optimization decisions.
The study further emphasizes the importance of using realistic test scenarios, such as querying,
creating, removing, and updating data, to simulate actual user activities and gain practical
insights into the impact of design patterns on software performance (Langsari et al., 2018).
Additionally, the study highlights the use of the ISO/IEC 25010 standard for assessing quality
attributes, including performance efficiency, which helps developers understand the broader
implications of design patterns on software quality (Langsari et al., 2018). Comparative analysis
between legacy and refactored systems also plays a significant role in identifying the specific
benefits and trade-offs associated with the application of design patterns (Langsari et al., 2018),
in addition to providing critical insights into the tangible benefits of implementing design
patterns in terms of both efficiency and maintainability.
Design patterns play a pivotal role in enhancing software efficiency, especially through their
application within the refactoring process. Design patterns offer structured solutions to common
design challenges which can significantly improve the performance efficiency of the software
application. Especially when applied throughout the refactoring process, legacy systems can
experience more efficient operations as design patterns can optimize the aspects of the software
such as response time and resource utilization (Langsari et al., 2018).
Refactoring, when combined with design patterns, provides additional benefits, including the
reorganization of the software's internal structure without altering its external behavior. This
makes the software easier to understand and modify, which can lead to improved performance
outcomes (Langsari et al., 2018). The study includes a systematic approach to dynamic
6|Page
performance measurement, comparing performance metrics before and after the application of
design patterns. This approach demonstrates that design patterns can lead to measurable
improvements in software throughput and response times (Langsari et al., 2018). The research
also highlights that when performance issues arise, the structured nature of design patterns makes
it easier to isolate and resolve these issues without extensive code changes.
Additionally, design patterns help manage the complexity of software systems by providing
reusable solutions, contributing to a more maintainable codebase. This maintainability indirectly
boosts performance efficiency by enabling quicker updates and optimizations (Langsari et al.,
2018). The study also categorizes software quality attributes, with performance efficiency being
critical for enterprise applications. Design patterns significantly contribute to these attributes,
ensuring that software meets both user expectations and performance requirements (Langsari et
al., 2018).
However, the study also acknowledges that while design patterns generally enhance
performance, they can introduce additional layers of abstraction that may negatively impact
performance in some scenarios. Therefore, careful consideration and balanced application of
design patterns are necessary to ensure that their benefits outweigh any potential drawbacks
(Langsari et al., 2018). This study underscores the idea that maintainable code is not just about
reducing future maintenance costs but also about creating software that performs efficiently from
the outset.
Design
Scenario
Car Rental Management System
Description
The code is designed to manage the operations of a rental car business. In this scenario the rental
company has a number of cars available for rent by the customers for a set number of days. The
7|Page
details of the cars such as the unique number, color, model and daily rental rate is tracked by the
system, in addition to the management of rental transactions which includes calculating the cost
of each rental and keeping track of whether the car is currently rented out or available to be
rented by a customer.
Simple Solution
8|Page
Class Diagram
The class diagram for the basic code snippet consists of three main classes: Car, Rental, and
CarRentalSystem, further explained underneath:
Car Class:
This class represents a car available for rental. Each car has attributes like number, color,
model, and dailyRate.
The Car class has a one-to-one relationship with the Rental class, meaning that each
rental is associated with one specific car.
Rental Class:
9|Page
The Rental class represents the act of renting a car. It contains attributes like the number
of rental days and a Boolean, isRented to track whether the car is currently rented or
returned.
The rental status is an important feature, allowing the system to determine whether a car
is available or already rented.
The Rental class calculates the total rent due based on the daily rate of the associated car
and the number of rental days.
The Rental class is associated with the Car class in a one-to-one relationship, as each
rental corresponds to a single car.
CarRentalSystem Class:
This class manages all the rentals within the system. It contains a list of Rental objects,
establishing a one-to-many relationship with the Rental class.
The CarRentalSystem allows the addition of new rentals and can display all current
rentals.
Java implementation (without using design patterns)
10 | P a g e
Figure 1: Screenshot of Car Class 1
11 | P a g e
Figure 2: Screenshot of Car Class 2
12 | P a g e
Figure 3: Screenshot of Rental Class 1
13 | P a g e
Figure 4: Screenshot of Rental Class 2
14 | P a g e
Figure 5: Screenshot of Rental Class 3
15 | P a g e
Figure 6: Screenshot of CarRentalSystem Class
Refined Solution
Problem: The Rental class calculates the rent due using a straightforward multiplication of days
rented and daily rate.
This solution lacks optimization for more complex scenarios such as applying discounts,
handling varying rates, or dealing with different rental durations. As the rental system scales to
include more complex pricing rules, manual calculations can become inefficient and error-prone.
16 | P a g e
2. Lack of Efficient Status Handling
Problem: The rental status is managed with a boolean flag, making it difficult to handle more
complex scenarios.
The basic solution does not support efficient management of different rental statuses (e.g.,
overdue, maintenance required) or complex rental rules. This can lead to inefficiency when
trying to handle some cases or when the system needs to perform additional operations based on
rental status.
Problem: The basic system does not incorporate any caching or optimization techniques.
Without techniques such as caching frequently accessed data or optimizing data retrieval, the
system may suffer from performance bottlenecks. For example, repeatedly querying the list of
rentals or recalculating rent due for each request can be inefficient.
Combining multiple responsibilities within a single class can lead to inefficiencies. For example,
if the system needs to handle additional operations or integrate with other systems, the
monolithic design can make a performance bottleneck. Additionally, the lack of separation of
concerns can increase complexity, making the system harder to maintain and optimize.
Problem: Common operations such as adding rentals, calculating due rents, and displaying
rentals are handled directly without optimization.
If these operations are frequent and the dataset is large, the lack of optimization can lead to
performance issues. For example, iterating through a large list of rentals to calculate due rent or
display information can be inefficient without proper data structures or algorithms.
17 | P a g e
Chosen Design Patterns
The State pattern simplifies transitions and state management, increasing efficiency. The State
pattern enables the Rental class to assign state-specific behaviors to different state classes
(AvailableState, RentedState, etc.) rather than utilizing complicated conditional logic within a
single class. By avoiding repetitive checks and updates, this modular approach increases
efficiency and lowers the complexity of the Rental class. Additionally, it facilitates the extension
or modification of state behaviors without affecting other system components, which helps in
ensuring system performance as it expands.
Efficiency is increased through the Facade pattern, which offers a simplified interface for
frequent tasks. Managing numerous components directly is reduced by encapsulating complex
interactions and multiple method calls under the CarRentalFacade. By reducing the number of
unnecessary or inefficient method calls, this abstraction improves overall performance by
streamlining the rental, return, and due calculation processes. It also makes the system more
reliable and efficient by lowering the chance of errors and enhancing maintainability.
Class Diagram
18 | P a g e
Diagram 2: Class Diagram of Refined Solution
The refined code snippet enhances the basic design by incorporating the State and Facade design
patterns. The main components of the class diagrams remain the same, with the addition of
RentalState, AvailableState, RentedState, and CarRentalFacade classes.
Car Class:
The Car class remains unchanged, continuing to represent the properties of individual
cars available for rent.
The Rental class has been refactored to use the State pattern. It now contains a reference
to a RentalState object that represents the current state of the rental (either AvailableState
or RentedState).
The Rental class can change its behavior dynamically based on its current state by
delegating tasks to the RentalState object. This makes the system more flexible and
capable of handling additional states in the future.
The RentalState interface defines the behavior that each state of a rental should
implement.
AvailableState, RentedState and AvailableState are concrete implementations of the
RentalState interface, each defining the specific behavior for when a rental is available or
rented.
The Rental class transitions between these states as necessary, allowing it to respond to
events like renting or returning a car.
CarRentalSystem Class:
19 | P a g e
The CarRentalSystem class continues to manage rentals, but it now interacts with rentals
that are state-aware, meaning they can dynamically adjust their behavior based on their
state.
The CarRentalFacade class provides a simplified interface to the client, encapsulating the
complex interactions between Rental, Car, and CarRentalSystem.
The Facade pattern makes it easier for clients to perform operations like renting,
returning cars, and calculating due rent without needing to interact directly with the
underlying system’s complexity.
This class interacts with multiple rentals and the CarRentalSystem, managing operations
at a higher level of abstraction.
20 | P a g e
Figure 7: Screenshot of Car Class 1
21 | P a g e
Figure 9: Screenshot of Rental Class 1
22 | P a g e
Figure 11: Screenshot of CarRentalSystem Class
23 | P a g e
Figure 14: Screenshot of RentedState Class
24 | P a g e
Figure 16: Screenshot of CarRentalFacade Class
25 | P a g e
Figure 17: Screenshot of Main Class 1
26 | P a g e
Figure 18: Screenshot of Main Class 2
References
Barbacci, M., Klein, M. H., Longstaff, T. A., & Weinstock, C. B. (1995). Quality
Attributes. Carnegie Mellon University.
Abdullah, F. (2017). Evaluating impact of design patterns on software maintainability
and performance. https://www.duo.uio.no/handle/10852/60024
Tigulla, A. R., & Kalidasu, S. S. (2015). Evaluating Efficiency Quality Attribute in Open
Source Web browsers. Evaluating Efficiency Quality Attribute in Open Source Web
Browsers. http://www.diva-portal.se/smash/get/diva2:829868/FULLTEXT01.pdf
Langsari, K., Rochimah, S., & Akbar, R. J. (2018). Measuring Performance Efficiency of
Application applying Design Patterns and Refactoring Method. IPTEK Journal of
Proceedings Series, 4(1), 149. https://doi.org/10.12962/j23546026.y2018i1.3527
27 | P a g e
28 | P a g e