Replies: 4 comments 1 reply
-
@valentinacupac would you like to share your thoughts here? |
Beta Was this translation helpful? Give feedback.
-
@pulkitent I only use the keyword "interface" (Java & .NET) in the following cases:
Now in the past, I did have interfaces for nearly everything (that was back in the days when I was testing classes in isolation, so I'd put all the collaborators as interfaces). I don't do that anymore. |
Beta Was this translation helpful? Give feedback.
-
Agree with @valentinacupac here. We can actually simplify that rule with:
Abstracting I/O (e.g., Ports in the Hexagonal Architecture) are always interfaces for testability purposes, if nothing else. However, even inside your Domain, you may have interfaces representing abstractions. For example, with a "pizza ordering system" you might have a bunch of different toppings that can go on a pizza, as well as other options (deep dish? corn meal crust? thick crust? etc.), all of which affect pricing, so they all may implement a p.s. If you see lots of classes ending in |
Beta Was this translation helpful? Give feedback.
-
YAGNI is about deferring choice to the last responsible moment so you can focus on delivering value right of the bat. To be able to let you defer this kind of choices, your code need to be modular and have low coupling. Thus, YAGNI forces you to have a more modular code to be a able to replace it later with a real implementation whenever the right technology has been chosen. Hence the needed interface to abstract away your program intent :) |
Beta Was this translation helpful? Give feedback.
-
YAGNI (You aren't going to need it) rule says we should have the minimum number of elements in our code to do the job.
But whenever I create a class it's recommended that we should first create an interface and then extend it by having a child class as per the principle "Program to interfaces rather than concrete implementations" so that I can accommodate future requirements better and have more loosely coupled code.
But according to YAGNI, from the beginning, we should avoid creating unnecessary interfaces.
So which to follow and when to follow? Usecase?
Beta Was this translation helpful? Give feedback.
All reactions