java - Is loosely coupling more reliable (based on lookup API from netbeans)? -


i've seen netbeans platform development tutorial videos (now known trails) (http://www.netbeans.org/kb/trails/platform.html)

and i've been wondering how stable using lookup netbeans

this understood how lookup works

as image :

enter image description here

as psudo code (class stucture):

{  ((class implements myinterface)) , ((class b implements myinterface))   [myinterface (api)]  [coreapplication] ([lookup provide access , b via myinterface ])  } 

my question above implementation creates reliable outcome compared heavily coupled (also think of scenario static variables,methods , inner classes accessed other classes) ?

[i need know if use loosely coupling , use lookup api implement it. program become more or less reliable compared tightly coupled one. (by reliable mean factors stability of application, crash often, etc)]

if how works ?

i'd (also) depends on if it's reliable.

think it. have class b registered in lookup, class needs service class b able provide. class wants service, doesn't matter if implementation class b, class c, class d or whatever. so, using lookup ask if service available , use if is. , here comes reliability. let's service you're looking cannot found within lookup, it's make sure system won't break if service cannot found.

a scenario in netbeans this:

requiredservice s = lookup.getdefault().lookup(requiredservice.class); if (s != null) {     s.dosomething(); // in case responsibility of reliability lies on side of implemented service. } else {     // it's keep reliable , perhaps let user know went not expected. } 

now imagen "tightly" rely on implementation of requiredservice , of sudden, reason, it's not there anymore. since modules loaded @ runtime within netbeans, you'll classloader exceptions , won't have chance make decision in such cases.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -