Question on the use of Lookup

Please use a mailing-list, see http://gephi.org/developers/
Post Reply
littleBobbyTables
Posts: 8
Joined: 10 Jun 2016 18:19

Question on the use of Lookup

Post by littleBobbyTables » 11 Jul 2016 15:43

I wasn't quite sure where to put this question, so I'm putting it here. I am trying to figure out the point of using Lookup in the Gephi toolkit to create things like the ProjectController and the GraphModel. I can't find a lot of documentation on how Lookup is used, and I'm trying to determine if it could relate to a small problem my program is having. I would greatly appreciate any help on figuring out why this is used, and if it's not necessary what could be used in its place. Thanks!

Alarmwolf
Posts: 1
Joined: 12 Aug 2016 13:13

Re: Question on the use of Lookup

Post by Alarmwolf » 12 Aug 2016 13:40

Hi, may be my comment will be too late, but anyway) Lookup is one of the things that may really confuse you at the beginning of Gephi (and Netbeans Platform).
'Lookup' is one of mechanisms of Netbeans Platform, that helps modules to get their dependencies. Instead of creating some objects (like ProjectController) by yourself (with 'new ...') you just saying 'Give me ready instance of ProjectController' in code like:
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);

The best and short description of this tool I saw in the next cheatsheet:
https://dzone.com/refcardz/netbeans-platform-70

This mechanism saves developer of new modules from handy creating or long searching of heavy objects, because logic of their lifecycle can be very complex, but it isn't interesting for developer, he just needs object with its api :) For example, may be it's wrong to have 2 ProjectControllers in application - Lookup will find existed instance and give it to us.

This pattern is one of implementations of 'Inversion of control' design principle.

Please correct me if I said something wrong)

Post Reply