AOOP Theory
AOOP Theory
Design patterns in java are reusable solutions to common software design problems.
They follow Object oriented principles and can broadly categorized into three types.
These design patterns are used to deal with object creation, ensuring proper
instantiation.
• Singleton Pattern: Ensures that a class has only one instance and provides a
global access point for the entire class with just one instance.
• Factory Method Pattern: Provides a Way to allocate instantiation to its
subclasses. Opposite of singleton pattern.
These design patterns are used to deal with communication and responsibilities
between objects.
Junit is a widely used testing framework in java for writing unit tests to verify
functionality of a code.
J-Unit annotations:
• @Test: Marks the method as test case. This method is executable by Junit
framework.
• @BeforeEach: Executes before each test method in the class. Used to setup.
• @AfterEach: Executes after each test method. Useful for cleaning up.
• @BeforeAll: Runs only once before all test methods in the class. Typically used
to initialize shared across test.
• @AfterAll: Runs only once after all test methods in class. Used to release
resources.
• @Disable: skip a test method or class.
• @RepeatedTest: runs a test multiple time.
• @ParameterizedTest: Enables different inputs to test with.
Chain of Responsibility:
SOLID Principles:
SOLID principles are a set of five design principles in Object Oriented Programming
aiming to make software more maintainable, flexible and scalable.
Code Smells:
Code smells are indicators of potential problems in codes that are not necessarily bugs
but can cause problems over time. Code smells doesn’t mean the code itself is
incorrect, but likely inefficient, hard to maintain, not easily scalable.
Bloaters:
Bloaters are a type of Code smells that indicates that the code has grown excessively or
unnecessarily large, making it difficult to understand and maintain.
Examples of Bloaters:
• Long Methods: Methods that are too long, making them hard to understand.
• Large Classes: Classes that are trying to do too much and accumulate many jobs
or responsibilities.
• Primitive Obsession: Overly relying on primitive data types (int, double, etc.)
• Long Parameter List: Methods having too many parameters.
These smells arise when object-oriented principles (SOLID, etc.) are misapplied,
ignored leading to code not taking full advantage of the paradigm.
Examples of Object-Oriented Abusers:
Stream API:
Stream API in java provides a modern way to work with collections of data in a
functional style.
Used for processing collection of data. It supports operations like filtering, mapping,
and reducing data in declarative style.
Streams are lazy and operate on demand, enabling efficient processing for potential
large database.
Lambda Expressions: