Enforcing noninstantiability to Utility Classes in OFBiz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Enforcing noninstantiability to Utility Classes in OFBiz

Rishi Solanki
Hello Team,
Recently I came across the guideline given for the Utility classes by
Joshua Bloch (Effective Java author).
Quick Reference -
http://www.informit.com/articles/article.aspx?p=1216151&seqNum=4

Now I have a question on the pattern we are using for the most of the
utility classes which only have the static methods, mentioning few of them
here;
- CatalogWorker.java
- CategoryWorker.java
- ProductWorker.java
- UtilMisc.java
etc.

Here in any of the class we do not have the instance methods/attributes,
and user (client) of these class may try to instantiate the object of these
class as default constructor auto applies to them, also some may tries to
extend them to add their own utility methods. We should fix this, that
means in OFBiz we do not take such kind of patch or code which will create
the instance of these classes, but we should also enforce the client of
these classes to do not instantiate and extends these classes.
We in OFBiz tries to do this in some classes like StringUtil.java by
enforcing the singleton property with the private constructor, but the
final instance of StringUtil have been used in FreeMarkerWorker.

Please let me know your thoughts on this, and if agree then I will create
Jira and submit the patch.

--
Rishi Solanki
Manager, Enterprise Software Development
HotWax Media Pvt. Ltd.
Direct: +91-9893287847
http://www.hotwaxmedia.com
Reply | Threaded
Open this post in threaded view
|

Re: Enforcing noninstantiability to Utility Classes in OFBiz

Adrian Crum-3
That sounds good to me. I have noticed other places in OFBiz where a
utility class has been used improperly, but at the moment I can't think
of where those are.

Feel free to upload patches to Jira. All code improvements are welcome!

-Adrian

On 11/15/2011 2:08 PM, Rishi Solanki wrote:

> Hello Team,
> Recently I came across the guideline given for the Utility classes by
> Joshua Bloch (Effective Java author).
> Quick Reference -
> http://www.informit.com/articles/article.aspx?p=1216151&seqNum=4
>
> Now I have a question on the pattern we are using for the most of the
> utility classes which only have the static methods, mentioning few of them
> here;
> - CatalogWorker.java
> - CategoryWorker.java
> - ProductWorker.java
> - UtilMisc.java
> etc.
>
> Here in any of the class we do not have the instance methods/attributes,
> and user (client) of these class may try to instantiate the object of these
> class as default constructor auto applies to them, also some may tries to
> extend them to add their own utility methods. We should fix this, that
> means in OFBiz we do not take such kind of patch or code which will create
> the instance of these classes, but we should also enforce the client of
> these classes to do not instantiate and extends these classes.
> We in OFBiz tries to do this in some classes like StringUtil.java by
> enforcing the singleton property with the private constructor, but the
> final instance of StringUtil have been used in FreeMarkerWorker.
>
> Please let me know your thoughts on this, and if agree then I will create
> Jira and submit the patch.
>
> --
> Rishi Solanki
> Manager, Enterprise Software Development
> HotWax Media Pvt. Ltd.
> Direct: +91-9893287847
> http://www.hotwaxmedia.com
>
Reply | Threaded
Open this post in threaded view
|

Re: Enforcing noninstantiability to Utility Classes in OFBiz

Rishi Solanki
Thanks Adrian, I will submit the patch by this week.
I hope this is fine.

--
Rishi Solanki
Manager, Enterprise Software Development
HotWax Media Pvt. Ltd.
Direct: +91-9893287847
http://www.hotwaxmedia.com


On Tue, Nov 15, 2011 at 8:02 PM, Adrian Crum <
[hidden email]> wrote:

> That sounds good to me. I have noticed other places in OFBiz where a
> utility class has been used improperly, but at the moment I can't think of
> where those are.
>
> Feel free to upload patches to Jira. All code improvements are welcome!
>
> -Adrian
>
>
> On 11/15/2011 2:08 PM, Rishi Solanki wrote:
>
>> Hello Team,
>> Recently I came across the guideline given for the Utility classes by
>> Joshua Bloch (Effective Java author).
>> Quick Reference -
>> http://www.informit.com/**articles/article.aspx?p=**1216151&seqNum=4<http://www.informit.com/articles/article.aspx?p=1216151&seqNum=4>
>>
>> Now I have a question on the pattern we are using for the most of the
>> utility classes which only have the static methods, mentioning few of them
>> here;
>> - CatalogWorker.java
>> - CategoryWorker.java
>> - ProductWorker.java
>> - UtilMisc.java
>> etc.
>>
>> Here in any of the class we do not have the instance methods/attributes,
>> and user (client) of these class may try to instantiate the object of
>> these
>> class as default constructor auto applies to them, also some may tries to
>> extend them to add their own utility methods. We should fix this, that
>> means in OFBiz we do not take such kind of patch or code which will create
>> the instance of these classes, but we should also enforce the client of
>> these classes to do not instantiate and extends these classes.
>> We in OFBiz tries to do this in some classes like StringUtil.java by
>> enforcing the singleton property with the private constructor, but the
>> final instance of StringUtil have been used in FreeMarkerWorker.
>>
>> Please let me know your thoughts on this, and if agree then I will create
>> Jira and submit the patch.
>>
>> --
>> Rishi Solanki
>> Manager, Enterprise Software Development
>> HotWax Media Pvt. Ltd.
>> Direct: +91-9893287847
>> http://www.hotwaxmedia.com
>>
>>
Reply | Threaded
Open this post in threaded view
|

Re: Enforcing noninstantiability to Utility Classes in OFBiz

Rishi Solanki
Hi,
I have created Jira issue and provided patch here -
https://issues.apache.org/jira/browse/OFBIZ-4656

Sorry for delay in action.

--
Rishi Solanki
Manager, Enterprise Software Development
HotWax Media Pvt. Ltd.
Direct: +91-9893287847
http://www.hotwaxmedia.com


On Wed, Nov 16, 2011 at 4:47 PM, Rishi Solanki <[hidden email]>wrote:

> Thanks Adrian, I will submit the patch by this week.
> I hope this is fine.
>
>
> --
> Rishi Solanki
> Manager, Enterprise Software Development
> HotWax Media Pvt. Ltd.
> Direct: +91-9893287847
> http://www.hotwaxmedia.com
>
>
> On Tue, Nov 15, 2011 at 8:02 PM, Adrian Crum <
> [hidden email]> wrote:
>
>> That sounds good to me. I have noticed other places in OFBiz where a
>> utility class has been used improperly, but at the moment I can't think of
>> where those are.
>>
>> Feel free to upload patches to Jira. All code improvements are welcome!
>>
>> -Adrian
>>
>>
>> On 11/15/2011 2:08 PM, Rishi Solanki wrote:
>>
>>> Hello Team,
>>> Recently I came across the guideline given for the Utility classes by
>>> Joshua Bloch (Effective Java author).
>>> Quick Reference -
>>> http://www.informit.com/**articles/article.aspx?p=**1216151&seqNum=4<http://www.informit.com/articles/article.aspx?p=1216151&seqNum=4>
>>>
>>> Now I have a question on the pattern we are using for the most of the
>>> utility classes which only have the static methods, mentioning few of
>>> them
>>> here;
>>> - CatalogWorker.java
>>> - CategoryWorker.java
>>> - ProductWorker.java
>>> - UtilMisc.java
>>> etc.
>>>
>>> Here in any of the class we do not have the instance methods/attributes,
>>> and user (client) of these class may try to instantiate the object of
>>> these
>>> class as default constructor auto applies to them, also some may tries to
>>> extend them to add their own utility methods. We should fix this, that
>>> means in OFBiz we do not take such kind of patch or code which will
>>> create
>>> the instance of these classes, but we should also enforce the client of
>>> these classes to do not instantiate and extends these classes.
>>> We in OFBiz tries to do this in some classes like StringUtil.java by
>>> enforcing the singleton property with the private constructor, but the
>>> final instance of StringUtil have been used in FreeMarkerWorker.
>>>
>>> Please let me know your thoughts on this, and if agree then I will create
>>> Jira and submit the patch.
>>>
>>> --
>>> Rishi Solanki
>>> Manager, Enterprise Software Development
>>> HotWax Media Pvt. Ltd.
>>> Direct: +91-9893287847
>>> http://www.hotwaxmedia.com
>>>
>>>
>