quarta-feira, 28 de setembro de 2016

Inversion of Control? Ok! Gonna try!

These past weeks a friend of mine has been sending me lots of links to videos, articles and posts about Dependency Injection and, naturally, inversion of control. It turns out that a week ago, I finished the very, very very minimal code needed to start Suna in c++:

  • A LocalHost class
  • A Channels class
  • An unreliable communication channel class
  • A wanna-be 3way handshake for starting connections on “application level”, by using UDP.

There’s enough stuff in there to start getting lost as I forget the code, but since it IS still small enough, I’ve decided to try to use a few of the concepts from inversion of control. Took a while to refactor nearly everything:
  • ISocket, IEndpoint, IHost, INetworkPacket, Ietcetc. So many interfaces…
  • Constructor arguments, constructor arguments, constructor arguments….
  • Now it’s really easier to change stuff around.

      Overall, I’m liking the results even though I’m hating all the boilerplate code. It became clear that I need some kind of injector to spawn instances of my concepts, so later I’ll write some kind of abstract factory. Suna is meant to be a really small project, so probably a “poor man dependency injection” will be enough.

Nenhum comentário:

Postar um comentário