Skip to content
Advertisement

Tag: design-patterns

Replacing if else statement with pattern

I have a if else statement which might grow in the near future. Since, this is already looking messy, I think it would be better if I can apply any design patterns here. I looked into Strategy pattern but I am not sure if that will reduce if else condition here. Any suggestions? Answer This is a classic Replace Condition

Handling an exception as a method argument

I am looking for a design pattern to handle Exception instances received as method arguments. To put some context into the question, I am using GWT and have various asynchronous handlers that usually come in a form similar to: So, the onFailure method receives a Throwable instance that I need to handle. Now, I have a number of exceptions I

Abstract class extends concrete class

I earlier learned that abstract class can extend concrete class. Though I don’t see the reason for it from JAVA designers, but it is ok. I also learned that abstract class that extends concrete class can make overriden methods abstract. Why? Can you provide with use case where it is useful? I am trying to learn design patterns and I

Java object, changed fields listener, design-pattern

There is a class: Then we update some fields How can I know which fields of MyClass were tried to be changed (invoked, in the example above field1 and field2)? What is the best solution for that? Maybe some design-pattern? One option is to create HashSet of changed fields for this object as an additional property and update it inside

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 once rather than circularly . i’m not sure whether because of the environment of my system. but if i add one line code in the method meta

Advertisement