Promoting structure reuse – does OOP really help?

I have become involved in some commercial Java development in the past month; consequently, my perception of Java as a counterproductive language has been changing to mediocre rather than anything else. I have been feeling uneasy about developing in Java mostly due to constant self-repetition in the code that I write. Forget the trivial lack of automatic getters/setters (as seen in C#) – this uneasiness comes from the style of the language.

When programming in the Object-Oriented Style, your primary concern is to model your domain as closely as possible – creating objects for concepts like Account or Position. However the model of the real world is never so simple so as to be modeled by an acyclic graph of classes that inherit from superclasses (if you have that kind of domain, consider yourself lucky). Generally there are some cross-cutting concerns that can be found across your subclasses – and however minor, they are difficult to separate from the rest of the code. Nor would you want to – having logic sprinkled across a myriad of superclasses is not exactly the epitome of good design or maintainability. (Maybe this has something to do with the fact that when we model the domain, for different subclasses it is generally the case that the Liskov substitution principle is violated – as the behaviour of different subclasses is intended to be different! A solution to this would be to spill abstract methods into interfaces and keep the concrete methods the same – but this again comes at the cost of naming complexity, amongst other detrimental effects).

Sometimes it is necessary to bite the bullet, and use copy-and-paste, then change a line in a method or two. This isn’t exactly DRY, and any errors in code that has been copied (verbatim or not) will propagate across different parts of your program.

Perhaps the most relevant question is whether any programming language could do better – whether copy-and-pasting could be avoided without the nice, clean design you originally started with. I believe to know of a language that could help in this respect – Factor. Below I will give an intuitive reasoning as to why this kind of programming language helps.

In Factor, arguments to “functions” are passed implicitly on the stack. Much of the benefit from using a functional concatenative language is derived from the fact that functions do not need any context, just their arguments in the correct order on top of the stack. This in turn means that a word (the term for “function” used in concatenative languages) could do just the kind of small data-fiddling that we need to have in our Java program in order to follow DRY. But of course, unlike Java – the word does not need to know any extraneous information – it takes the minimum structures it needs to perform its work. Sounds like reuse, does anybody disagree?

If anybody would like an example – I could post one on here.