GROUP 5 PRESENTATION Slide OF LECTURE 2-Compressed

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

SOLID

Lecture-2
Student ID Deep Dive in Design Principles
1805016
1805035
1805045
1805048
1805051
1805056
SOLID is a set of principles that
were introduced by Robert C.
Martin in the early 2000s as a
guide for object-oriented
software design. The principles
are meant to help software
developers create software that
is easy to understand, maintain,
and modify.
Deconstructing SOLID
Deconstructing SOLID
But…they are often inseparable
Oops…wrong diagram :p
Refactoring
Refactoring is the process of making minor, incremental changes to
existing code to enhance its readability, maintainability, and
performance. It entails renaming variables, extracting methods or
classes, reducing duplication, simplifying difficult conditionals,
enhancing naming standards, and many other things. It is a vital
aspect of the software development process and necessitates careful
design, testing, and documentation.
Logging
Logging is a vital tool for developers since it allows them to understand the behavior of
their code and troubleshoot problems during runtime. It can also assist track user
activity, detect security breaches, monitor performance, and verify compliance with
legislation and standards. Logging gives useful insights into the behavior of code and
assists developers in improving the quality, dependability, and security of their systems.
Log files are a valuable tool for developers to connect with the production environment,
offering a common language, repeatability, collaboration, feedback, and
documentation. Log files can be shared with other developers, testers, and support staff
to improve cooperation and troubleshooting, offer feedback, discover patterns and
trends, and act as documentation. By leveraging log files, developers can ensure that
they are working closely and delivering high-quality software that meets the needs of
users.
Logging
Caching
Caching is an efficient approach to increase an application's
performance by lowering the time and resources required to
conduct specific tasks. It can minimize data access time,
network traffic, database load, enhance scalability, and ensure
the system can manage huge levels of traffic without becoming
overloaded.
Storage
Encapsulation
Fixing SRP Violation
Common SRP
Violation
SRP states that each class should
have a single responsibility, and that
responsibility should be entirely
encapsulated by that class.
It's common to see logging
statements scattered throughout
business logic classes.

Logging
Issue
Scattered Logging Vision Effect
We can create a separate We only need to update the
If we decide to change “StoreLogger” class, and all
storage class that is
the format of our logs of the code that uses it will
responsible for handling all
or switch to a different automatically use the
of the logging functionality.
logging library, we updated functionality. This
like “StoreLogger”. Relevant
would need to update conforms to the SRP
methods would take
every single logging principle because each class
parameters to specify the
statement in every has a single responsibility.
message text, severity level,
single class.
and any other relevant
information.
An example of SRP Violation
THE METHOD
Updating Logging Introducing
libraries and StoreLogger class
messages

Scattered SRP violation Encapsulation


Logging complete
Adding StoreLogger class
Enabling Encapsulation
Common SRP Violation
in Caching

We use in-memory caching


in our application, it can
work well in small-scale
environments.
According to SRP, each class
should have a single task
that is totally contained
within that class.
Issue
Scalability Vision Effect
If we need to scale our
application by adding We can create a By using the “StoreCache”
multiple servers, it becomes “StoreCache” class, which class, we can centralize the
incompatible as each server will encapsulate the caching caching mechanism and
will have its own cache, functionalities and hide the make it easier to switch to a
which can lead to
implementation details from different caching system if
inconsistent data across needed. We can simply
the servers. We may need to
other classes. This class
update the “StoreCache”
use distributed caching, can use a distributed
class with the new caching
such as Redis, which can caching library, and provide
library and our application
work across multiple a set of caching functions will continue to work without
servers. However, this that can be used by other the need to change code in
creates a problem of SRP
classes as needed. multiple places.
violation.
An example of SRP Violation
THE METHOD
Scaling the Introducing
application StoreCache class

In-Memory SRP violation Encapsulated


Caching Distributed
Caching complete
Adding StoreCache class
Enabling Encapsulation
THE INTERNAL STRUCTURE WILL NOT CHANGE THROUGH OUT THE CODE BASE
We are open to extending the behaviour of the functionality
Two ways to achieve this :

1.Inheritance : 2.Composition:
INHERITANCE
An example of open closed through inheritance
We can add a new behaviour of database storage without changing the
internal structure
Classes and objects created through inheritance are tightly coupled
because changing the parent or superclass in an inheritance relationship
risks breaking your code
FOR EXAMPLE

You might also like