For the last year I've been mostly using Java. After having a lot of experience with C#, its events, delegates, lambdas and generics, Java feels pretty weird. One of the most important things about Java is their "as is" approach to "everything is an object" concept. If you want something, it definitely should be an object. If you want an object, you either have to have a factory (to build composites) or build a new class.
It appears that the modern object-oriented approach to software design should be declared like this:
- You build a number of small silly classes. Every class should incarnate the only concept.
- You create objects of your classes and wire them together, depending on logic you want. The idea is, you're normally payed for implementing complicated concepts, so you have to describe the problem in terms of your primitive concepts. At this point you have an object graph (or network) where nodes are simple processors aimed to solve simple problems. This network has input and output nodes.
- You then take your input data (mouse movements, HTTP-requests, whatever) and pass it to the input node(s) of your network. Then you read network's output and send it back (UI animations, HTTP-reponses, ...)
This approach is encouraged by GoF
, P of EAA
and others. There's a number
of IoC containers
to help with wiring objects together, there are mock object
frameworks aimed to help with testing individual classes/objects and their impact to the dependencies.
But, frankly, after trying to write code accepting all these values, I have a feeling that something's wrong:
- I build classes like PersonNameFormatter which have the only method -
format(String firstName, String lastName).
- I build a plenty of small classes, which are sweet as long as you see them individually.
- I think in terms of "I want a doer" instead of "I need to do".
- Looks like I'm not that far from using the concept of "evaluators" everywhere: IfEvaluator, ForEachEvaluator, etc.
- When I try to understand how the whole application works, the only idea that comes to mind is: "well, it works somehow, there are sweet small classes, and then objects are created and wired, it should just work".
And even more frankly, I think that writing terrible procedural code with 500 LoC procedures should not be considered that bad.