❔ Static interface methods
I have several classes implementing my Codec interface like this:
Is there a better way to represent multiple actions (
Encode
and Decode
) without using a class?
- If there would have been a single method, I would start using a delegate. But a delegate can't do multiple things
- This is essentially just logic, so having this in a class is a bit useless (and makes me want to turn this into a singleton because instances aren't necessary)
So basically looking to eliminate the redundancy of a class (because I only need 1 instance) here while having those 2 functions combined (with a delegate somehow?)6 Replies
Not sure what you mean by "eliminate the redundancy of a class"
C# is object-oriented
It will use classes whether you like it or not
(also, interfaces should start with capital
I
)Maybe you are looking for default interface methods
Default interface methods - C# 8.0 draft feature specifications
This feature specification describe the syntax updates necessary to support default interface methods. This includes declaring bodies in interface declarations, and supporting modifiers on declarations.
eh I guess
sometimes I lean more towards the functional approach
but it's fine
just dislike the boilerplate
mhehe
I don't
Java is my main language so I don't wanna learn myself this
eh I cleaned up the classes a bit with the methods with
=>
and it looks fine now I guessWell, you're using C# not Java
So use C# conventions
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.