Skip to main content

All Questions

Tagged with
0 votes
1 answer
529 views

Design pattern for system retrieving data about an entity and updating it

I've come across the following situation multiple times when writing code (especially webapps) and would like to know the best practice (possibly design patterns) to solve it correctly: My data is ...
Markus B's user avatar
0 votes
0 answers
508 views

Can't access Superclass method on subclass object

I have problem with inheritance in Java - with accessing Superclass method on a subclass Object. I didn't find any solution on StackOverFlow, but there are multiple posts with the same title which don'...
Baseer's user avatar
  • 1
0 votes
1 answer
109 views

How to make a Linear Search OOP approach that uses Input Scanner

So I refactored a Linear Search code that only uses the main method. My goal is to convert it into an OOP approach. But I have trouble saving the input set of integers. // LinearSearchDriver.java ...
peaky's user avatar
  • 1
-1 votes
1 answer
265 views

How to refactor this enum into OOP?

I'm studying for a test at the moment and I'm struggling with this question The questions follows: A) Suppose one would like to add an object BY_TWELVE to the enumeration without change the structure ...
user avatar
2 votes
1 answer
119 views

Refactoring in Java: Duplicated attributes

I am supposed to refactor duplicated attributes in Student class. I have Student and Professor classes as below. I am really confused about how to do refactoring with attributes. Should I add a new ...
B. Selin Zaza's user avatar
2 votes
2 answers
768 views

Design pattern for state-based entity handling

My question is about what should be the most OOP solution and the right design pattern for my situation. We have a user entity and multiple account entities belong to the user. Account entities can ...
Five's user avatar
  • 388
1 vote
1 answer
395 views

How to ensure that future Implementations of an Interface will also extend a particular Class

I have an abstract class and two final classes that extend it. The abstract class is also an implementation of an interface. Now I have to remove one of the two child classes and add an interface so ...
Vanil Mar's user avatar
0 votes
2 answers
95 views

How can I write an interface for a place where I obviously can have abstact class but I need an interface?

I have an abstract class that is extended by a final class with very closed implementation(private fields, methods, security oriented). There is a switch-case that depending on some input chooses ...
Vanil Mar's user avatar
0 votes
2 answers
250 views

Best way to refactor this code, if enums are not extensible

Consider the following class that represent a entity and has method which return data of type EnumA EntityA class: public class EntityA { public Set<EnumA> getProcessedFlags() { ... } } ...
Vivek Ranjan's user avatar
0 votes
1 answer
103 views

My code violates the DRY principle, but unsure about how to proceed with refactoring

I am very new to OOP, and have written some classes in Java which are used to convert a double value between different units of length, however I realized that I violated the DRY principle by having ...
Nick Barnes's user avatar
0 votes
2 answers
162 views

How to avoid using instanceof in MVC Architecture

I'm developing a game like Pacman in Java and I am currently facing these code smells which I do not like. Let me explain my thinking: my game is set up on a MVC architecture. On the view module I ...
Gonçalo Teixeira's user avatar
-1 votes
2 answers
279 views

If the requirements can change in future, is it a good idea to pull the business rules out of the code into a custom rule engine?

We have a requirement such that Users need to be presented different facts based on some constraints. Similar Hypothetical Example If User belongs to Australia and earns more than 10k$ then show XYZ ...
Acharya's user avatar
  • 19
0 votes
1 answer
389 views

Implement Filter Design Pattern for generic cases (i.e. filter specific String attributes)

I'm implementing a slight variation of this design pattern (filter) https://www.tutorialspoint.com/design_pattern/filter_pattern.htm What I came across, is that I need to filter a String attribute (...
JulianP's user avatar
  • 97
2 votes
2 answers
2k views

How to refactor two classes with very similar methods but using different types

I'm trying to master the refactoring for a project I'm working on right now. Basically I have two classes which each extend from an interface. If you take a look at my code, you can observe that ...
j panton's user avatar
  • 242
-2 votes
1 answer
57 views

Polymorphism instead of conditional transition with generics

I have some code. I found some posts on "Refactor the code in OOP-code without using if/else, switch/case or ? operators. Please, help me use it with generics. I spent too much time, but can't find ...
Slav's user avatar
  • 9

15 30 50 per page