cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Factory method subclassing cayenne data objects
Date Mon, 02 Mar 2009 00:46:22 GMT

I'm trying to implement a factory method pattern based on a cayenne data object. 

Say for example i have a class (cayenne based) called Artist, i want to make a subclass of
Artist, say ExpertArtist that implements some specific behavior.

Actually i have a big static Factory class that give me the all objects, i have a method like

        public static Artist getArtist(String id) {

                if (id == null || id.equals(""))
                        return null;

                DataContext context = DataContext.getThreadDataContext();

                Artist object = (Artist) DataObjectUtils.objectForPK(
                                context, Artist.class, Integer.parseInt(id));
                return object;

Obviously i can declare ExpertArtist as an subclass of Artist.


public class EspertArtist extends Artist {	
    public String getName() {
        return super.getName() + " i'am expert !!";

I've tried to instantiate an ExpertArtist, just modifying the Factory method, with no results.
I don't know how to bouild the parent class calling super or something...

Obviously these are not the real classes, the actual classes are really big and this solution:
just modifying the factory method is the best for me.


View raw message