JaroslavTulach at 08:49, 23 March 2009 - 2009-03-23 08:49:16

←Older revision Revision as of 08:49, 23 March 2009
Line 20: Line 20:
[[Category:APIDesignPatterns:Clarity]]
[[Category:APIDesignPatterns:Clarity]]
 +
[[Category:APIDesignPatterns]]

Apidesign at 20:30, 27 December 2008 - 2008-12-27 20:30:39

←Older revision Revision as of 20:30, 27 December 2008
Line 19: Line 19:
On the other hand, as [[Singletonizer]] pattern shows, using this style in [[ProviderAPI]], where the ''open'' is done once by the [[API]] infrastructure is quite OK.
On the other hand, as [[Singletonizer]] pattern shows, using this style in [[ProviderAPI]], where the ''open'' is done once by the [[API]] infrastructure is quite OK.
-
[[Category:APIDesignPatterns:Accuracy]]
+
[[Category:APIDesignPatterns:Clarity]]

JaroslavTulach at 14:29, 26 December 2008 - 2008-12-26 14:29:52

←Older revision Revision as of 14:29, 26 December 2008
Line 7: Line 7:
<source lang="java" snippet="misuse.prjconfig.correct.trivial.access"/>
<source lang="java" snippet="misuse.prjconfig.correct.trivial.access"/>
-
no longer compiles. Instead of it one needs to either use the [[OpenMethod]]:
+
no longer compiles. The problem is that '''provider''' is of unknown bound '''<?>'''. Whenever it is used, the compiler uses new ''unknown bound'', as such the call to getter returns one unknown type and the setter needs another unknown type. They are not the same. To work around that, one needs to create new [[OpenMethod]]:
<source lang="java" snippet="misuse.prjconfig.correct.openmethod"/>
<source lang="java" snippet="misuse.prjconfig.correct.openmethod"/>
-
or [[OpenClass]]:
+
which ''opens'' the provider parameter and binds it to '''<C>''' bound. All references to that variable then represent the same type during the method execution or during existence of [[OpenClass]] instance:
<source lang="java" snippet="misuse.prjconfig.correct.openclass"/>
<source lang="java" snippet="misuse.prjconfig.correct.openclass"/>

JaroslavTulach at 14:23, 26 December 2008 - 2008-12-26 14:23:41

←Older revision Revision as of 14:23, 26 December 2008
Line 5: Line 5:
The '''getActive''' and ''setActive''' methods could take '''ProjectConfiguration''' class as parameter, but that would not be correct - it would allow a user of the [[API]] to take configuration from one project and try to activate it on different one. By use of ''<Configuration extends ProjectConfiguration>'' bound, this is prevented. Yet, this very complicates life of clients of this API, as following code:
The '''getActive''' and ''setActive''' methods could take '''ProjectConfiguration''' class as parameter, but that would not be correct - it would allow a user of the [[API]] to take configuration from one project and try to activate it on different one. By use of ''<Configuration extends ProjectConfiguration>'' bound, this is prevented. Yet, this very complicates life of clients of this API, as following code:
-
<source lang="java" snippet="misuse.prjconfig.orig"/>
+
<source lang="java" snippet="misuse.prjconfig.correct.trivial.access"/>
no longer compiles. Instead of it one needs to either use the [[OpenMethod]]:
no longer compiles. Instead of it one needs to either use the [[OpenMethod]]:

JaroslavTulach: New page: When dealing with objects that produce and consume generic type of unknown bounds, it is necessary to ''open'' the type before its use. One can either use an OpenMethod or... - 2008-12-25 16:26:09

New page: When dealing with objects that produce and consume generic type of unknown bounds, it is necessary to ''open'' the type before its use. One can either use an OpenMethod or...

New page

When dealing with objects that produce and consume [[Generics|generic type]] of unknown bounds, it is necessary to ''open'' the type before its use. One can either use an [[OpenMethod]] or, in case the open needs to last longer than just during method execution, an [[OpenClass]].

Imagine a [[Generics|generified]] API to access project configuration:
<source lang="java" snippet="misuse.prjconfig.correct"/>
The '''getActive''' and ''setActive''' methods could take '''ProjectConfiguration''' class as parameter, but that would not be correct - it would allow a user of the [[API]] to take configuration from one project and try to activate it on different one. By use of ''<Configuration extends ProjectConfiguration>'' bound, this is prevented. Yet, this very complicates life of clients of this API, as following code:

<source lang="java" snippet="misuse.prjconfig.orig"/>

no longer compiles. Instead of it one needs to either use the [[OpenMethod]]:

<source lang="java" snippet="misuse.prjconfig.correct.openmethod"/>

or [[OpenClass]]:

<source lang="java" snippet="misuse.prjconfig.correct.openclass"/>

This is very annoying and definitely not [[Cluelessness|clueless]]! As such exposing patterns that require [[OpenClass]] or [[OpenMethod]] to [[ClientAPI]] users is not really recommended.

On the other hand, as [[Singletonizer]] pattern shows, using this style in [[ProviderAPI]], where the ''open'' is done once by the [[API]] infrastructure is quite OK.

[[Category:APIDesignPatterns:Accuracy]]