Posts

Design Pattern

 SOLID Single Responsibility There should not be more than one reason for a class to change. Class provides focused responsibility. Questions -  What is this class supposed to do ? And what this class is doing? Open Closed Software Entities(Classes, Modules, Methods etc.) should be open for extension, but closed for modification. We should be able to extend the existing behaviour. Whatever is already written should not be change, we should not be modifying the code written in base class. Liskov Substitution We should be able to substitute base class objects with derived class object & this should not alter behaviour/characteristics of program.  Ex - Extending Rectangle to create Square.  Interface Segregation Clients should not be forced to depend upon the interface that they do not use. Interface Pollution -  No large interfaces,  Unrelated, Classes have empty method implementations. Method implementations throw UnsupportedOperationException (or ...

JAVA | Exception Handling | Introduction

Image
2 Next Level Developer · Post JAVA | Exception Handling | Introduction Posting as Paritosh Agrawal Update Revert to draft Preview Close ComposeHTML Link Introduction: An Exception is nothing but an exceptional or unexpected event that may occur during the program execution. Examples : Invalid input: ValidationException File does not exist: FileNotFoundException Exceptions are categorised into 3 categories. Checked exceptions Unchecked exceptions Errors Checked exceptions:  occurs at the compile time, also called as compile time exceptions. programmer is supposed to handle these exception. Example:  https://ideone.com/80B30I Unchecked exceptions:  occurs at the time of execution, also called as Runtime exceptions. Runtime Exception includes  bugs, such as logic errors or improper use of an API. Example:  https://ideone.com/ZqWh7X Java Exception Hierarchy :  Was this article helpful? Plea...

IOC(Inversion Of Control)

What is IOC(Inversion Of Control): Allowing your clients to define and use dependency of your service instead you defining it. Example You are creating a service called TextEditor and you want to use an open source library for spell check.  Client ----> Service ----> Dependency There are two ways you can do this. Define dependency in you service and let client do not worry about that. Create Instance on Dependency and let client decide which dependency to use. Let's understand each way through code snippet along with pros and cons.  1. Define dependency in you service and let client do not worry about that: Service: Service will look like public class TextEditor { private SpellChecker checker; public TextEditor() { this.checker = new SpellChecker(); } } Client: Client will use service like TextEditor textEditor = new TextEditor(); Pros: Your client does not need to worry or know about spell checker. Cons ...