These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: AbstractFactory
PostPosted: Mon Dec 01, 2008 6:13 am 
Newbie

Joined: Thu Jun 26, 2008 9:21 am
Posts: 2
Hi all, I have a question about an AbstractFactory class I need and I am using NHibernate version 2.0.1.GA to reach the goal.

I want to have a factory for different classes based on IFactory. At the moment it looks like this:

Code:
    public class AbstractFactory<T> where T : IFactory
    {
        private static AbstractFactory<T> instance = null;

        public static AbstractFactory<T> Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new AbstractFactory<T>();
                }

                return instance;
            }
        }

        public T Get(string name)
        {
            T inst = default(T);

            // look if there is already an instance with
            // the wanted name.
            foreach (T t in items)
            {
                if (t.Name.Equals(name))
                {
                    inst = t;
                    break;
                }
            }

            if (inst == null)
            {
                // create instance of T
                object obj = System.Activator.CreateInstance(typeof(T));
                inst = (T)obj;
                inst.Name = name;

                items.Add(inst);
            }

            return inst;
        }

        private IList<T> items = new List<T>();
    }


And I want to use it like this:

Code:

            ExchangableContainer container = new ExchangableContainer();

            // saving of a new created instance of ExchangableContainer must fail,
            // because we need to set some members of the class.
            ClassTester<ExchangableContainer>.SaveMustFail(container);

            // define a new container type
            ExchangableContainerType type = AbstractFactory<ExchangableContainerType>.Instance.Get("Restmüll");
            type.Capacity = 1000;

            container.Type = type;
            ClassTester<ExchangableContainer>.SaveMustSucceed(container);



So in the end I need to have one Factory for some Types. Each of this type should be saved in a different table e.g. list_<objname>. What kind of Nhibernate.Attributes do I need to use? If you need more details, just ask.

thanks,
ac


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.