[go: up one dir, main page]

0% found this document useful (0 votes)
8 views4 pages

AOOP Theory

Uploaded by

nikhilkolli010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

AOOP Theory

Uploaded by

nikhilkolli010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Design patterns:

Design patterns in java are reusable solutions to common software design problems.
They follow Object oriented principles and can broadly categorized into three types.

Creational design patterns:

These design patterns are used to deal with object creation, ensuring proper
instantiation.

Types of Creational patterns:

• 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.

Structural Design Patterns:

These design patterns are used to composition and organization of objects.

Types of Structural Design Patterns:

• Adapter Patterns: Allows multiple incompatible and different interfaces and


classes to work together.
• Decorator Patterns: Allows Adding multiple functionalities to an object
dynamically.

Behavioral Design Patterns:

These design patterns are used to deal with communication and responsibilities
between objects.

Types of Behavioral Design Patterns:

• Observer Patterns: Used to create one-to-many dependency between objects.


• Strategy Patterns: Used to create a family of algorithms and make them
interchangeable.
• Template Patterns: Used to define base functions in main class but allows
subclasses to modify specific steps of these functions.
• Command Patterns: Used to encapsulate a request as an object, allowing
parameterization of object with requests.
J-Unit:

Junit is a widely used testing framework in java for writing unit tests to verify
functionality of a code.

J-Unit annotations:

Its annotations simplify test configuration, execution and management.

• @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:

Chain of Responsibility is a behavioral design pattern that allows a request to be passed


along a chain of handlers. Each handler in the chain processes the request or passes it
along to the next handler in the chain. This pattern prevents the sender of a request
from necessarily knowing which handler will handle their request.

SOLID Principles:

SOLID principles are a set of five design principles in Object Oriented Programming
aiming to make software more maintainable, flexible and scalable.

1. Single Responsibly Principle:


• A class should only have only one job or responsibility.
• It is used to help make the code more maintainable.
2. Open/closed Principle:
• The code should be open to extension but should be close for
modification.
•This increases the functionality of code while decreasing the chance for
bugs.
3. Liskov substitution Principle:
• Objects of super class should be replaceable with objects of subclasses
without effecting functionality.
• Ensures interchangeability between parent and child class.
4. Interface Segregation Principle:
• Clients should not be forced to depend on interfaces they don’t use.
• Creates cleaner and maintainable code.
5. Dependency Inversion Principle:
• High-level modules should not depend on low level modules, it should be
other way around and abstractions should not depend on details, details
should depend on abstractions.
• Makes code more flexible.

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.

Object Oriented Abusers:

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:

• Switch Statements: Overuse of switch or if statements behavior. Makes code


harder to extend.
• Refused Bequest: A subclass doesn’t use the methods or properties of its super
class. Indicates improper hierarchy.
• Temporary Field: parameters or methods that are used only once in the entire
code. Increases the size of code.
• Alternative classes with different interfaces: different classes that do similar
things but have inconsistent interfaces. Lead to inefficiency.

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:

Lambda expressions simplify defining inline implementation of functional interfaces


making code smaller and expressive.

It is a concise way to represent an anonymous function that can be passed as a


parameter.

You might also like