9 crucial Java Design Principles you cannot miss
1/9 What is Encapsulation ?
Much of object programming is centered on
minimizing the ripple effects caused by changes to a
program. This is done simply by keeping details
secret The principal ways of doing this are:
- minimizing visibility - private fields, package-private
classes (grouping into 1 domain package:
entity,repository,service,controller)
- generic references (polymorphism) - using high
level references (interfaces or abstract classes)
instead of low level references (concrete classes)
2/9 What is Polymorphism ?
The point of polymorphism is that you can subclass a
class and the objects implementing those subclasses
will have different behaviors for the same methods
defined in the superclass (and overridden in the
subclasses).
3/9 What is Aggregation / Composition ?
has-a relationship
4/9 What is Method Overloading ?
If a class has multiple methods by same name but
different parameters
5/9 Inheritance vs Compositions ?
inheritance - Java doesnt support multiple inheritance
(till java 8 , where we have default methods )
composition - Use private members
inh - you need super class instance
comp - easy to create Mock Object representing composed class
inh - it breaks encapsulation, when behavior of super class changes,
functionality in sub class may get broken
comp - you are flexible enough to replace implementation of
Composed class with better and improved version.
inh - Inheritance makes much sense like when a genuine parent child relation exists
comp
- In Decorator pattern, we dont extend any class to add additional functionality
Instead we keep an instance of the class we are decorating
and delegates original task to that class after doing decoration
6/9 What is DRY ?
avoid duplication for functionality , use dependency injection if needed.
but you can repeat same code (ie user authorization) for different functionalities in micro services or micro functionalities
7/9 What is Dependency Injection ?
Class injected by DI framework is easy to test with mock object
Easier to maintain because object creation code is centralized in framework
Done in Spring via proxies
8/9 What is Delegation ?
delegate tasks to ie:
equals, hashcode methods, thread pools
do not do it yourself on client side
9/9 What is Law of Demeter / Principle of least
knowledge ?
9 crucial Java Design Principles you cannot miss

More Related Content

DOCX
Hibernate3 q&a
PDF
Bea weblogic job_interview_preparation_guide
PDF
Java interview questions
PPTX
Technical Interview
PDF
Technical interview questions
PPT
Java interview-questions-and-answers
PDF
50+ java interview questions
PPT
Design pattern
Hibernate3 q&a
Bea weblogic job_interview_preparation_guide
Java interview questions
Technical Interview
Technical interview questions
Java interview-questions-and-answers
50+ java interview questions
Design pattern

What's hot (17)

PDF
Core java interview questions
PDF
Java Interview Questions
PDF
Best interview questions
PDF
Java j2ee interview_questions
PDF
Hibernate Interview Questions
DOCX
Java questions with answers
PPTX
Spring andspringboot training
PDF
Extreme Interview Questions
PPTX
Dev labs alliance top 20 basic java interview question for sdet
PDF
Top 100 Java Interview Questions with Detailed Answers
PPT
8 most expected java interview questions
DOC
24 collections framework interview questions
PDF
Ee java lab assignment 4
DOCX
Brouchure
PPSX
Spring - Part 3 - AOP
PPTX
Hibernate
PDF
Hibernate Advance Interview Questions
Core java interview questions
Java Interview Questions
Best interview questions
Java j2ee interview_questions
Hibernate Interview Questions
Java questions with answers
Spring andspringboot training
Extreme Interview Questions
Dev labs alliance top 20 basic java interview question for sdet
Top 100 Java Interview Questions with Detailed Answers
8 most expected java interview questions
24 collections framework interview questions
Ee java lab assignment 4
Brouchure
Spring - Part 3 - AOP
Hibernate
Hibernate Advance Interview Questions
Ad

Similar to 9 crucial Java Design Principles you cannot miss (20)

PPTX
Object Oriented, Design patterns and data modelling worshop
PDF
Oops concepts
PPT
Object Oriented Concepts and Principles
PPTX
SKILLWISE - OOPS CONCEPT
PDF
Top 30 Technical interview questions
PPTX
Concepts of oops
PPTX
OOPs in Java
PPT
Jump Start To Ooad And Design Patterns
PPS
Jump start to OOP, OOAD, and Design Pattern
PPT
Oop concepts
PPTX
JAVA PROGRAMMING FOR BCA SECOND SEMESTER
PPTX
Introduction To Design Patterns Class 4 Composition vs Inheritance
PPTX
Clean Code I - Best Practices
PPTX
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
PPTX
Introduction to oop
PPTX
OOP Presentation.pptx
PPTX
OOP Presentation.pptx
PPT
P Training Presentation
PPT
Oops Concepts
PPTX
Object Oriented Concept
Object Oriented, Design patterns and data modelling worshop
Oops concepts
Object Oriented Concepts and Principles
SKILLWISE - OOPS CONCEPT
Top 30 Technical interview questions
Concepts of oops
OOPs in Java
Jump Start To Ooad And Design Patterns
Jump start to OOP, OOAD, and Design Pattern
Oop concepts
JAVA PROGRAMMING FOR BCA SECOND SEMESTER
Introduction To Design Patterns Class 4 Composition vs Inheritance
Clean Code I - Best Practices
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Introduction to oop
OOP Presentation.pptx
OOP Presentation.pptx
P Training Presentation
Oops Concepts
Object Oriented Concept
Ad

More from Mark Papis (8)

PDF
Java Concurrency Starter Kit
PDF
Java Streams Interview short reminder with examples
PDF
Java vs Web security Cheat Sheet
PDF
Java technical stack Cheat Sheet
PDF
Spring cheat sheet
PDF
Java JVM Memory Cheat Sheet
PDF
Java inheritance cheat sheet
PDF
Java Collections comparison Cheat Sheet
Java Concurrency Starter Kit
Java Streams Interview short reminder with examples
Java vs Web security Cheat Sheet
Java technical stack Cheat Sheet
Spring cheat sheet
Java JVM Memory Cheat Sheet
Java inheritance cheat sheet
Java Collections comparison Cheat Sheet

Recently uploaded (20)

PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
LMS bot: enhanced learning management systems for improved student learning e...
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PPTX
Internet of Everything -Basic concepts details
PDF
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
PPTX
future_of_ai_comprehensive_20250822032121.pptx
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
Electrocardiogram sequences data analytics and classification using unsupervi...
PDF
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
PPTX
SGT Report The Beast Plan and Cyberphysical Systems of Control
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
SaaS reusability assessment using machine learning techniques
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
Enhancing plagiarism detection using data pre-processing and machine learning...
LMS bot: enhanced learning management systems for improved student learning e...
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
4 layer Arch & Reference Arch of IoT.pdf
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Internet of Everything -Basic concepts details
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
future_of_ai_comprehensive_20250822032121.pptx
Early detection and classification of bone marrow changes in lumbar vertebrae...
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Electrocardiogram sequences data analytics and classification using unsupervi...
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
SGT Report The Beast Plan and Cyberphysical Systems of Control
giants, standing on the shoulders of - by Daniel Stenberg
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
Rapid Prototyping: A lecture on prototyping techniques for interface design
SaaS reusability assessment using machine learning techniques
NewMind AI Weekly Chronicles – August ’25 Week IV

9 crucial Java Design Principles you cannot miss

  • 2. 1/9 What is Encapsulation ? Much of object programming is centered on minimizing the ripple effects caused by changes to a program. This is done simply by keeping details secret The principal ways of doing this are: - minimizing visibility - private fields, package-private classes (grouping into 1 domain package: entity,repository,service,controller) - generic references (polymorphism) - using high level references (interfaces or abstract classes) instead of low level references (concrete classes)
  • 3. 2/9 What is Polymorphism ? The point of polymorphism is that you can subclass a class and the objects implementing those subclasses will have different behaviors for the same methods defined in the superclass (and overridden in the subclasses).
  • 4. 3/9 What is Aggregation / Composition ? has-a relationship
  • 5. 4/9 What is Method Overloading ? If a class has multiple methods by same name but different parameters
  • 6. 5/9 Inheritance vs Compositions ? inheritance - Java doesnt support multiple inheritance (till java 8 , where we have default methods ) composition - Use private members inh - you need super class instance comp - easy to create Mock Object representing composed class inh - it breaks encapsulation, when behavior of super class changes, functionality in sub class may get broken comp - you are flexible enough to replace implementation of Composed class with better and improved version. inh - Inheritance makes much sense like when a genuine parent child relation exists comp - In Decorator pattern, we dont extend any class to add additional functionality Instead we keep an instance of the class we are decorating and delegates original task to that class after doing decoration
  • 7. 6/9 What is DRY ? avoid duplication for functionality , use dependency injection if needed. but you can repeat same code (ie user authorization) for different functionalities in micro services or micro functionalities
  • 8. 7/9 What is Dependency Injection ? Class injected by DI framework is easy to test with mock object Easier to maintain because object creation code is centralized in framework Done in Spring via proxies
  • 9. 8/9 What is Delegation ? delegate tasks to ie: equals, hashcode methods, thread pools do not do it yourself on client side
  • 10. 9/9 What is Law of Demeter / Principle of least knowledge ?