paint-brush
Was this an Original Invention?by@Codename_One
211 reads

Was this an Original Invention?

by Shai AlmogMay 27th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

A while back I “invented” what might be an original approach to custom component creation. I haven’t seen it used anywhere else so I think I invented it but in all probability someone must have come up with it first.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Was this an Original Invention?
Shai Almog HackerNoon profile picture

A while back I “invented” what might be an original approach to custom component creation. I haven’t seen it used anywhere else so I think I invented it but in all probability someone must have come up with it first.


As a teenager I had great faith in my own originality (this predated the spread of the internet which disproved that) I always had a venture I was working on whether in robotics or my BBS etc. In most I used different variations of a brand name I believed to be uniquely my own…I carried this belief into my early 20’s where it suddenly occurred to me to register the domain to my venture. Not only was my original domain name (and every variation) already taken 20 years ago. The guy running one of the first domains had his picture in the site and he physically looked like me!

This leads me to my point: originality is rare. I find the lack of originality comforting. It means instead of focusing on original thought I can focus on high quality execution of the idea. I find that a lot of entrepreneurs share my view of originality although not all.

E.g. Codename One is a continuation of LWUIT which in itself took ideas from Swing and a few other sources. That means developers had a common base to build on: shoulders of giants.

Is this Original?

I was discussing this with a friend the other day and he took the opposite view to mine. He claimed that original ideas are more common than what I would normally consider. He asked me whether I had an idea in the past that I think I invented but don’t know for sure. I was personally curious about one: Lead Components.

So we are both really curious, is this something that existed before I came up with it?

If not would it have been applicable in other frameworks (I think it would).

So this is Where we Need your Help…

I haven’t seen this concept used anywhere outside of Codename One and LWUIT. I think this is a powerful UI design paradigm and I’ll be pretty happy if other frameworks pick that up. But what I’d like to know is: “was this a truly original idea or did someone think about it before me”?

I’ve worked with a lot of UI frameworks and haven’t seen anything like lead component but maybe I saw something and forgot or maybe I missed something completely and reinvented it. If you know of something that looks like this I’d appreciate a link with a date of inception if available. Lead Components were launched in LWUIT a while back but the first reference I found was from 2011. It’s hard to see the history now that java.net was removed.

So What’s a Lead Component?

When we construct UI’s we have components (widgets, view etc.) and containers (ViewGroup, collection, Controller etc.). It is common for Container to be a Component subclass (composite) thus allowing hierarchy.

So we can create a completely new component in two basic ways:

  • Create a Component subclass and implement the component from scratch
  • Create a Container that contains multiple components within to compose a standalone complex component

The second option is the one I want to discuss… Let’s say I want to create a button component with an icon on the left side and two rows of text so I create a Container and place the components within. I can style the container to look like a button but now I have problems:

  • Events are handled by each component separately, so when the button is pressed how do I know that the whole button is pressed?
  • Styling — the text might change color when the button is pressed. How do the two separate labels adapt to the shared state change?

These are big problems. They are solvable in a case by case basis with a lot of manual work but they require a nuanced approach.

Lead Component allows us to delegate the Containers state & events to one component within the hierarchy. This means that all components within the hierarchy will instantly delegate the “lead” to that one component.

Since that component would naturally already know how to handle states, events etc. you wouldn’t need to write any code and just “follow the leader”. So in the case above instead of using two labels for text lines we’d use a button and a label and then delegate leading to the button. You can then bind event listening to the internal button listeners as they would receive all event callbacks.

If you want more details and samples there is a section about them in our developer guide.

Are the Advantages Applicable for Other Frameworks?

I think so.

This might not be applicable to some web frameworks where UI and events might not map as above.

However, for most native frameworks and some web frameworks this should provide advantages of code reuse and simplicity. One of the motivations behind this is easy composing/reuse in the GUI builder. A lead component can be assembled entirely in GUI with no code whatsoever to produce very complex custom UI’s.

E.g. on Android Google could add a setLeadView which would allow a view to control the entire hierarchy within a ViewGroup.

Someone could potentially implement this externally to the framework but it would be pretty hard to do in a generic way as lead components require internal framework state and event control both of which are non-trivial.

Even if you don’t know about a framework that implemented this but are deeply familiar with a specific framework let me know if you think that framework doesn’t have this or if it has something similar. I’d be interested in some ideas on improving composite components in the future.