Click here to Skip to main content
15,884,627 members
Articles / Programming Languages / Java

To do or to doer.go()?

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
27 Jul 2012CPOL2 min read 7.3K   1
One of the most important things about Java is their "as is" approach to "everything is an object" concept.

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:

  1. You build a number of small silly classes. Every class should incarnate the only concept.
  2. You create objects of your classes and wire them together, depending on logic you want. The idea is, you're normally paid 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.
  3. 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.

Here's an interesting reading related with the topic:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionDescription Pin
Kenneth Haugland27-Jul-12 5:07
mvaKenneth Haugland27-Jul-12 5:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.