23459 Posts in 18906 Topics by 2877 members
|Go to End|
13 February 2013 at 11:44pm Last edited: 14 February 2013 12:16am
Hey guys. I want to create an abstract DataObject but as many know, the database builder (and likely other things) don't like this.
I think this would be a pretty useful feature to have, as without it, we have to take some weird steps around the lack of support.
What is the lead dev consensus on this? Is it worth working on, and if so, what version would you want it in?
14 February 2013 at 9:10pm
what version would you want it in?
This would be a change for 3.2 as 3.1 is in testing nearing release so probably too late to get something like this in as I'm not sure what would break. As far as I know, you cannot have an abstract class extend a non abstract class so you'd need to look at making the whole DO chain abstract (viewable data, I think Object already is). To me it makes semantic sense for it to be abstract (you don't create a DataObject, in that case you'd use ArrayData).
10 August 2014 at 10:55am
some of my classes, that extend DataObject (e.g. Product) have methods with exact the same content.
I want to outsource these methods in a parent class: MyDataObject.
My Product class should extend MyDataObject instead of extending DataObject directly,
but I'm not able to do that, I get the same Problem as described above. And I don't want MyDataObject to have a database table. Declaring MyDataObject abstract didn't help.
Is there another way to achieve this:
avoiding duplicate code
10 August 2014 at 1:31pm
@annap, in that case you want to look at DataExtensions (which can be added to your data object without adding a table) or look at PHP Traits (http://addons.silverstripe.org/add-ons/simonwelsh/trait-loader)
11 August 2014 at 8:44am
Yes, that helped me. Thank you. DataExtension works for me.
|Go to Top|