Hi Guys,
Once I have got a "null" error in a line of code which was trying to get "GenericDelegator". I have replaced it with Delegator and restarted app then an error is gone. So I am not sure if restart helped or GenericDelegator was the problem. I must say that it worked for ages with Generic in that line and I have it in a few classes as well which work without a problem, at least so far. I have made a search through whole ofbiz app and under framework, product, etc. found out that both of them are used but Delegator is used more widely and only a few classes use GenericDelegator. Should I consider to put a particular one depending on a specific case? How to determine which one to use? I would appreciate any ideas on this. Thank you. |
Hi Michael,
Huh? Your question is a bit weird. Delegator is an interface and the GenericDelegator is an implementation of the interface so you cannot do a Delegator delegator = new Delegator() for example. Now if your question is should I declare the above variable to be a Delegator or GenericDelegator then I believe this does not even need an OFBiz expert to answer you. You should always design by contract and write to your interfaces instead of your concrete classes. This is just basic OOP. Here are some references that might help: https://en.wikipedia.org/wiki/Design_by_contract http://www.javapractices.com/topic/TopicAction.do?Id=194 Taher Alkhateeb ----- Original Message ----- From: "masionas" <[hidden email]> To: [hidden email] Sent: Thursday, 11 June, 2015 2:51:37 PM Subject: Delegator vs. GenericDelegator Hi Guys, Once I have got a "null" error in a line of code which was trying to get "GenericDelegator". I have replaced it with Delegator and restarted app then an error is gone. So I am not sure if restart helped or GenericDelegator was the problem. I must say that it worked for ages with Generic in that line and I have it in a few classes as well which work without a problem, at least so far. I have made a search through whole ofbiz app and under framework, product, etc. found out that both of them are used but Delegator is used more widely and only a few classes use GenericDelegator. Should I consider to put a particular one depending on a specific case? How to determine which one to use? I would appreciate any ideas on this. Thank you. -- View this message in context: http://ofbiz.135035.n4.nabble.com/Delegator-vs-GenericDelegator-tp4669907.html Sent from the OFBiz - User mailing list archive at Nabble.com. |
Taher, I believe you are an expert and this is good that you know that interface can't be instantiated unless it is implemented in some particular class. My question was different though.
In ofbiz you can see both of these: 1) Delegator delegator = (Delegator) request.getAttribute("delegator"); delegator.findByAnd(...) 2) GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); delegator.findOne(....) I think in earlier versions it used to be mostly GenericDelegator which was used, but in later ones it has been changed to Delegator. But there are still some places with Generic. I was wondering if there is something like ofbiz best practice for using either one. |
Hi Michael,
It does not matter "how" you instantiate the object. The only difference in the example you provided is that you cast whatever you retrieve from a map instead of creating it with the "new" operator. Either way, the best practice remains as I mentioned in the earlier email so please do visit the links. You do not go "more specific" unless you absolutely need to as a general rule in any system for any reason, and not specifically for OFBiz. Taher Alkhateeb ----- Original Message ----- From: "masionas" <[hidden email]> To: [hidden email] Sent: Thursday, 11 June, 2015 5:12:53 PM Subject: Re: Delegator vs. GenericDelegator Taher, I believe you are an expert and this is good that you know that interface can't be instantiated unless it is implemented in some particular class. My question was different though. In ofbiz you can see both of these: 1) Delegator delegator = (Delegator) request.getAttribute("delegator"); delegator.findByAnd(...) 2) GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); delegator.findOne(....) I think in earlier versions it used to be mostly GenericDelegator which was used, but in later ones it has been changed to Delegator. But there are still some places with Generic. I was wondering if there is something like ofbiz best practice for using either one. -- View this message in context: http://ofbiz.135035.n4.nabble.com/Delegator-vs-GenericDelegator-tp4669907p4669913.html Sent from the OFBiz - User mailing list archive at Nabble.com. |
Hi Taher,
Well, I would not argue the well-known OOP conventions and completely agree with them. Like I said earlier though, my interest was particularly in context of Ofbiz code evolution and switching from "more specific" to "more general" rather than using "more general" from the start. I believe, in the version I have a snapshot of - the GenericDelegator was just not completely replaced by Delegator. This is where confusion went from. Anyway, I appreciate the time you spent on it, Taher. Thank you and have a good one. :) |
Hi Michael,
Most welcome :) please note some code in the framework is not up to standards. So this might throw you off sometimes. I remember we had a discussion once about how the widget system should be pure for example but then saw hundreds of places where you have ftl sprinkled. So i'm just giving you my opinion of best practices despite anomalies in the code. HTH and best of luck Taher Alkhateeb On Jun 11, 2015 6:06 PM, "masionas" <[hidden email]> wrote: > Hi Taher, > > Well, I would not argue the well-known OOP conventions and completely agree > with them. Like I said earlier though, my interest was particularly in > context of Ofbiz code evolution and switching from "more specific" to "more > general" rather than using "more general" from the start. I believe, in the > version I have a snapshot of - the GenericDelegator was just not > completely replaced by Delegator. This is where confusion went from. > Anyway, > I appreciate the time you spent on it, Taher. Thank you and have a good > one. > :) > > > > -- > View this message in context: > http://ofbiz.135035.n4.nabble.com/Delegator-vs-GenericDelegator-tp4669907p4669915.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
Free forum by Nabble | Edit this page |