So I’m learning to build a parser for a intro class for software design. I have built a tokenizer package that splits my input string into Token objects that have getters for both the value and type. I can also return a raw String for value and type of the current token. My public facing interface from the Tokenizer currently
Tag: design-patterns
How to implement a generic interface that extends another generic interface in Java?
I am new to Java and working on implementing generic interfaces and that’s where I’d love some help. I want to implement a generic interface in Java that extends another interface. This is how the current interface structure looks like – I want to implement the ItemsProviderInterface interface and provide a definition for convertInput(), convertResponse(), request() methods. Maybe something like
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 for inheritance, however, the fact that the inputs and outputs are different and are related to two lambdas, make me wonder if they should remain
How to structure code to prevent incompatible capture of ? extends _?
I was wondering what is the best way to structure code to ensure compiler knows in very simple cases that passed variable is of correct type. I have created very simple code where class O has its execute method execute that accepts some kind of payload (that extends class P) and performs some kind of operation. The thing is that
How to extract telemetry code from different methods? Decorator pattern? AOP?
We are using Application Insights to monitor different service calls in our applications. Data for Application Insights is provided by many different methods and classes but always in an identical way/by identical code fragments: How am I able to extract those wrapping try catch fragments to one point of responsibility? I took a look at the dacorator pattern but I
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: Blockquote Specifying modifications of interest explicitly. You can improve update efficiency by extending the subject’s registration interface to allow registering observers only for specific events of
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: There are 2 possible composite roots here (CompositeA and CompositeB) and one leaf component (Leaf). Here I define DTOs that will hold serialized data: Now if I use visitor pattern for serialization, I get something like this: and if I use instanceof this is the code that does
Refactoring code that contains multiple if conditions
Here is some code I’ve written to save a UrlEntity : The above code exists in a service class and looks unnecessarily complex. I’m attempting to refactor so that the intent is clear. This is a basic refactoring I’ve written: This refactoring does not improve the code substantially. Is there a code pattern or idiomatic way to refactor the method
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 …