Skip to main content

Questions tagged [polymorphism]

Polymorphism is about using objects of a type uniformly, regardless of their subtype.

0 votes
2 answers
140 views

A class that implements two interfaces that extend the same interface [duplicate]

I'll get straight to the point. I want to implement a class structure in Java similar to the one in the image. Am I falling into bad practice with this kind of diamond-shaped interface implementation?...
A. WW's user avatar
  • 11
4 votes
1 answer
247 views

How do I handle polymorphic domain models in a Clean Architecture data access layer?

Let's say I'm making a space 4X game (because I am!) and I have an ISpaceObject interface in my domain layer, with a number of classes such as Ship, Starbase, Planet, Wormhole, etc. implementing it. I ...
ekolis's user avatar
  • 577
5 votes
5 answers
970 views

Handling class specific behavior: polymorphism vs instanceof

I'm designing a system with different types of components, and I'm trying to decide whether to use polymorphism or instanceof checks for handling type-specific behavior. I see two possible approaches: ...
user avatar
7 votes
8 answers
937 views

Why is "one function do more than one thing" a disadvantage of "boolean parameter", but not in "polymorphism"?

According to Is it wrong to use a boolean parameter to determine behavior?, I know using boolean parameters to decide the behaviour is bad, for example, when using boolean parameters as the following: ...
wcminipgasker2023's user avatar
1 vote
7 answers
536 views

How do I cleanly keep track of the type of various objects implementing a common interface without reflection?

In my multiplayer game I keep track of each player's inventory. I have a class for each inventory action that extends the abstract class InventoryItem. I then polymorphically call use() on the ...
Marvin's user avatar
  • 222
2 votes
0 answers
81 views

How to deal with implementation specific implementation accross interface boundaries

What to do if you end up in the following situation The intent here is that b and c can be substitutable for a. The client creates a bar through foo_1, which later may be passed back to foo_1 through ...
user877329's user avatar
-3 votes
2 answers
346 views

Polymorphism with variable default argument count

I'm in the process of writing a library in Python, and I've run into a design problem concerning the use of polymorphism. I have an ABC with abstract method 'foo': class A(ABC): @abstractmethod ...
Jan van Wijk's user avatar
2 votes
3 answers
955 views

Should I still "replace conditional with polymorphism" if the condition is from dynamic load data?

I know there are already some questions about replacing if else with polymorphism, for example: Applying Replace Conditional with Composition in functional programming Is it wrong to use any type of ...
wcminipgasker2023's user avatar
2 votes
3 answers
321 views

How to retain the concrete type when writing base-class-oriented code?

A scenario often arises when attempting to make some existing code reusable. I introduce an interface to represent the commonality between some new feature I'm implementing and some existing ...
amarsha4's user avatar
  • 176
2 votes
1 answer
697 views

Domain models: Can they be an abstract class

When talking about having a rich domain model successfully, in real applications, it needs to, somehow, access some abstraction of complex functionality (instead of being a row state calculator the ...
Vitor Figueredo Marques's user avatar
3 votes
1 answer
392 views

How are interfaces implemented behind the scenes in the Go language?

I have read this article which indicates a double tuple structure, but it is unfortunately light on implementation details, which is what I am looking for. So... how are interfaces implemented in Go? ...
SRNissen's user avatar
  • 161
0 votes
0 answers
588 views

What is the Best Practice for handling multiple Entities that behave identically?

Because I have multiple entities with unique fields, I need multiple repositories for each one even though each Entity will be handled exactly the same. What is the best way to handle these separate ...
dbrewster's user avatar
  • 139
-1 votes
1 answer
345 views

Avoid use of the visitor pattern in this very common scenario

Let's assume we need to send a message, and to do so we would like our client to be concerned only with constructing the message (DTO) and using a facade service to send it. We already know that we ...
blow's user avatar
  • 109
0 votes
1 answer
198 views

How to decide what view to show if I use polymorphism in the Model?

I am making a game of Monopoly. I call a method in my Board class which returns the current players square object! E.g Old Kent Road. Euston, Chance , Free parking. I use polymorphism to decide upon ...
Kevin Greetham's user avatar
2 votes
3 answers
331 views

how to leverage overloading while keeping business logic out of models

I am running into a conflict between two best practice principles- overloading should be used instead of long chained if/else statements models should not contain business logic I am working on a ...
dbrewster's user avatar
  • 139

15 30 50 per page
1
2 3 4 5
14