Composition or Inheritance for classes with almost similar implementations but different input and outputs for methods?

I have the following classes, which have quite similar method implementations. Only the classes’ method inputs and outputs seem to be of different types. When I put it like this, it sounds like a case …

Observer – specifying modifications of interest explicitly – JAVA implementation

I asked here how I should handle the situation when I need to inform observers only when specific attribute of object changes. I received very nice reply with reference to GoF where is written: …

Java – violation of Liskov substitution principle?

I have the following code: interface Ops{ void remove(); } interface BeforeRemove{ void doBeforeRemove(); } class A implements Ops{ @Override public void remove() { System….

Best way to serialize composite – (design pattern)

I have following java code that is implementation of Composite Design pattern: //composite designed for type safety (all Leaf-only operations only in leaf) interface Component extends Visitable { …

Refactoring code that contains multiple if conditions

Here is some code I’ve written to save a UrlEntity : public UrlEntity saveUrlEntity(String longUrl, LocalDate dateAdded) { int urlLength = longUrl.length(); if (urlLength >= Constants….

Java built-in Observable push notifications

UPDATE Added the full code to make it easier to understand. I am trying to understand how to implement push vs pull notifications using Java built-in Observer. the Observable class has 2 methods …

Which design pattern for merging 2 methods they differ in one place

I wonder which design pattern should I use in my case: I have 2 endpoints that use 2 service methods, each very similar, they differ only in invoking some different methods from the same service: My …

How to create a self registering factory in Java?

Factory pattern violates the OCP principle because it uses if() statements, which implies that if any class is added then the factory class has to change, being against SOLID principles. Self …

ANTLR Visitor Implementation For ArrayInitVisitorImpl

I am trying to build a visitor implementation that will convert a string array to unicode. I am using the following grammar: grammar ArrayInit; init : ‘{‘ value (‘,’ value)* ‘}’ ; value : init …

Dynamically choosing which class to create object of from json

I have an interesting problem that I’m having trouble coming up with a clean solution for. My application reads collections of json objects that it needs to deserialize to this or that class type …