InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Article: Composite Oriented Programming with Qi4j

Posted by Rickard Öberg on Nov 20, 2008

Sections
Enterprise Architecture,
Architecture & Design,
Development
Topics
Qi4j ,
OOP ,
Java ,
Languages ,
Methodologies ,
Programming ,
JayView ,
Design ,
Modeling ,
Composite Oriented Programming

The goal of modeling domain concepts through objects set by OOP has for a long time been handled in insufficient ways. What is the fundamental problem with how we have tried to do this so far? Is there a better way to deal with it? In this article we introduce the concept of Composite Oriented Programming, and show how it avoids the issues with OOP and reignites the hope of being able to compose domain models with reusable pieces.

Read: Composite Oriented Programming with Qi4j

  • This article is part of a featured topic series on Java

13 comments

Watch Thread Reply

Nice.. by Sony Mathew Posted
Re: Nice.. by Rickard Öberg Posted
Get a feeling how it works ... by Georg Ragaller Posted
Ruby mix-ins by Carl Byström Posted
Re: Ruby mix-ins by Rickard Öberg Posted
Interesting to compare with... by Stephen Palmer Posted
Where is it useful? by Gregory Mostizky Posted
Re: Where is it useful? by Rickard Öberg Posted
Re: Where is it useful? by Rafael Forte Posted
Persistense issues by Ricardo Di Pasquale Posted
Sounds like Traits, as implemented in Scala by Dean Wampler Posted
Relations to Trygve Reenskaug's DCI? by Michael Haupt Posted
"Classes are dead" ... by Joubin Houshyar Posted
  1. Back to top

    Nice..

    by Sony Mathew

    I like the idea of bringing composites or Mixins to Java although I'm not sure about dispatch performance for something like this. Also liked the introduction of multi-module layers to object assembly and enforcing layer/module separation.

  2. Back to top

    Get a feeling how it works ...

    by Georg Ragaller

    ... and check out www.qi4j.org. Rickard in his modesty 'forgot' to mention it.

  3. Back to top

    Ruby mix-ins

    by Carl Byström

    How does this differ from Ruby's mix-ins?

  4. Back to top

    Interesting to compare with...

    by Stephen Palmer

    Design with composition instead of inheritance? Yes!

    Actor-Role and object inheritance patterns in Nicola's Streamlined Object Modeling (www.streamlinedmodeling.com) ...

    ... and with the Party,Place,Thing - Role pattern in Peter Coad's Java Modeling in Color with UML (dn.codegear.com/article/29871)

  5. Back to top

    Where is it useful?

    by Gregory Mostizky

    I am trying to like this but I do not understand where such an approach would be useful in a real world applications? I mean real applications are usually very focused - a person can be a developer or maybe a speaker, but if I am writing a bug tracking app I only need to model "assign to developer" behavior and I don't care if that developer can also speak well :) Without such examples this idea appears too "academical" for me.

    Gregory

  6. Back to top

    Re: Nice..

    by Rickard Öberg

    On performance, as always it will depend on your usecase if it is good enough or not. What I can say is that this technique is the same as I used in the SiteVision CMS, and which is now powering about 150 Swedish government websites, including one with a veeeery high load one day of the year: the IRS on income tax declaration day. The performance stats I got from that was more than good enough (overall performance of course does not solely depend on invocation performance though). But you should try it yourself. There are some microbenchmarks included in the source, so you can run that on your own machine for numbers.

  7. Back to top

    Re: Ruby mix-ins

    by Rickard Öberg

    Good question. I'm not a Ruby-developer so I don't know. One of the things that I think separates this implementation from most implementations though is the ability to use private mixins, i.e. mixins that are only available internally in the object (sort of like "public" and "private" methods in a regular class). This can be very useful to hide implementation details.

  8. Back to top

    Re: Where is it useful?

    by Rickard Öberg

    My experience from previous apps using this approach is that each object will often have a primary concern related to the domain, but then it might have 10+ mixins which are of the generic kind (identity, timestamps, ACL's, metadata, tree hierarchy, etc.). And if you have generic mixins it is also much easier to do generic UI's, which is almost the real gain, in terms of lines of code saved, since UI's tend to cost a lot in coding.

    For this reason I think the approach is generally applicable. It also allows you to think more in terms of roles (i.e. "how does the CLIENT want to perceive this object?") rather than the usual class-oriented thinking (i.e. "what am I?"). Role oriented modeling, which by nature is heavily interface-oriented, leads to better separation of concerns and more reusable code.

  9. Back to top

    Persistense issues

    by Ricardo Di Pasquale

    I'm planning to compose several domain models (several enterprise applications) developed by third party providers. I think it's a good idea to make a concept proof with Qi4j, but can I get bottlenecked fairly with persistence issues in a EJB3 enviroment?
    Thanks

  10. Back to top

    Sounds like Traits, as implemented in Scala

    by Dean Wampler

    This approach sounds like traits (www.iam.unibe.ch/~scg/Archive/Papers/Scha03aTra...), a form of which is implemented in Scala (lamp.epfl.ch/~odersky/papers/ScalableComponent....).

  11. Back to top

    Relations to Trygve Reenskaug's DCI?

    by Michael Haupt

    It looks a bit familiar.

  12. Back to top

    "Classes are dead" ...

    by Joubin Houshyar

    There are clearly some good ideas here, but an early warning sign of things to come is to compare "conception" with "realization". (C.f first 3 paragraphs of JSP's specification from Sun ..).



    @Mixins({DeveloperMixin.class, SpeakerMixin.class, AlumniMixin.class})
    public interface HumanComposite
    extends Developer, Speaker, Alumni, Composite
    {}


    Related:
    www.howtodothings.com/home-and-garden/a4417-how...


    Classes are dead. Long live interfaces!


    Related?
    www.youtube.com/watch?v=mriBc6NjUhg

  13. Back to top

    Re: Where is it useful?

    by Rafael Forte

    Hello Rickard,

    Is there any example of qi4j being used in a webapp with UI and persistence code? I am curious to see how developers could benefit from using COP in regular webapps and how it could change day-to-day design.

    Thanks,
    Rafael