3 ms·
This sounds a little like an intro to writing "Enterprise" code. Essentially each function has to be its own interface. And you probably need some factory funct
by maxxxxx 9y ago
This sounds a little like an intro to writing "Enterprise" code. Essentially each function has to be its own interface. And you probably need some factory functions in addition.
Why not provide a set of static functions for ByteUtils that behave in a specified way and be done with it?
- SideburnsOfDoom 9y agoThere's more than one language that will quite happy type convert back and forth between a function and an equivalent single-method interface e.g. "a function that returns an int" and "an interface with one method, a function that returns an int". Though "one method per interface" isn't the aim of the Interface Segregation Principle.
- hack2017 9y agoBecause a function is not a contract enough - it doesn't have a strong name at point of injection. But yeah, pure functions should be used way more often.
- maxxxxx 9y agoDoes everything need to be dependency injected ? Sometimes it seems this is more important than code that works.
- hack2017 9y agoNo, but you will have extremely hard time finding devs who can mix OOP and func effectively. Mostly it's factory-factory and but-muh-Haskell types.
- SideburnsOfDoom 9y agoYou can inject e.g. a Func<int, int, int> or an IAdder interface. Although they are for the sake of example equivalent, I prefer the latter for several related reasons: it gives the DI container a specific type name to work with and avoids complex setup there, it gives the person reading the code a lot more to work with when trying to understanding what the injected thing is used for, and Func<int, int, int> is very general - not all functions with this signature will be be a useful adder.
- maxxxxx 9y agoAgain, why does everything need to be dependency injected? Why not a simple function that adds two numbers? I see these codebases where everything is abstracted two and three times and I don't understand what this achieves other than adding a ton of complexity for even simple things.
- SideburnsOfDoom 9y agoI haven't seen your codebase so I can't answer if your codebase injects too many things to too few, injects the right things or not. It also depends on how big the codebase is, and how long people are going to continue working on it - i.e. "enterprisy" concerns. But injection is done for testability and flexibility.