BT

InfoQ Homepage News Article: Composite Oriented Programming with Qi4j

Article: Composite Oriented Programming with Qi4j

Bookmarks

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

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Nice..

    by Sony Mathew /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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.

  • Get a feeling how it works ...

    by Georg Ragaller /

    Your message is awaiting moderation. Thank you for participating in the discussion.

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

  • Ruby mix-ins

    by Carl Byström /

    Your message is awaiting moderation. Thank you for participating in the discussion.

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

  • Interesting to compare with...

    by Stephen Palmer /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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)

  • Where is it useful?

    by Gregory Mostizky /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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

  • Re: Nice..

    by Rickard Öberg /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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.

  • Re: Ruby mix-ins

    by Rickard Öberg /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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.

  • Re: Where is it useful?

    by Rickard Öberg /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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.

  • Persistense issues

    by Ricardo Di Pasquale /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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

  • Sounds like Traits, as implemented in Scala

    by Dean Wampler /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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....).

  • Relations to Trygve Reenskaug's DCI?

    by Michael Haupt /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    It looks a bit familiar.

  • "Classes are dead" ...

    by Joubin Houshyar /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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

  • Re: Where is it useful?

    by Rafael Forte /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.