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

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

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 …

What is the solution for the N+1 issue in JPA and Hibernate?

I understand that the N+1 problem is where one query is executed to fetch N records and N queries to fetch some relational records. But how can it be avoided in Hibernate?

Replacing if else statement with pattern

I have a if else statement which might grow in the near future. public void decide(String someCondition){ if(someCondition.equals(“conditionOne”)){ // someMethod(…

Head First Design Patterns – Combined Pattern

I’m reading the chapter 12 on the Combined Pattern in Head First Design Patterns. On page 541,the sample DJView,it cant’t run correctly in my computer.when i press the ‘start’, the program only sounds …