views:

32

answers:

3

i need a complex returning type. i have 4 class returning types COMPLEXTYPE must include Company, Muayene, Radyoloji, Satis because i must return data switch case situation how can i do? Maybe i need generic collections How can i do that?

  public class GenoTipController
    {
        public COMPLEXTYPE Generate(DataModelType modeltype)
        {
            _Company company = null;
            _Muayene muayene = null;
            _Radyoloji radyoloji = null;
            _Satis satis = null;
            switch (modeltype)
            {
                case DataModelType.Radyoloji:
                    radyoloji = new Radyoloji();
                    return radyoloji;
                    break;
                case DataModelType.Satis:
                    satis = new Satis();
                    return satis;
                    break;
                case DataModelType.Muayene:
                    muayene = new Muayene();
                    return muayene;
                    break;
                case DataModelType.Company:
                    company = new Company();
                    return company;
                    break;
                default:
                    break;
            }


        }
    }

    public class CompanyView
    {
        public static List GetPersonel()
        {
            GenoTipController controller = new GenoTipController();
            _Company company = controller.Generate(DataModelType.Company);
             return company.GetPersonel();

        }

    }



    public enum DataModelType
    {
        Radyoloji,
        Satis,
        Muayene,
        Company
    }

According to the enum type will produce class.

A: 

Why not derive classes _Muayene, _Radyoloji, and _Satis from class _Company and keep the common data members and functions (like GetPersonel) in _Company class?

Nayan
i want to return a oblect (from Radyoloji class or whicy modaltype send complexType) my class includes all types
programmerist
I feel, sorry to say, you have not given much though about the design. My solution, or even Jamiec's solution will do. And as Jamiec said, we are not able to understand your English. :) Sorry about that. Please state clearly what you need.
Nayan
+1  A: 

It seems like what you're after is an interface. The COMPLEXTYPE returned from your Generate method must all expose a method called GetPersonel according to the later code.

public interface ICompany
{
   List GetPersonnel();
}

Then your Generate method becomes:

public ICompany Generate(DataModelType modeltype)

And each of your 4 classes (Radyoloji,Satis,Muayene,Company) must implement this interface.

Jamiec
i re arrange my ques look below :i want to return a oblect (from Radyoloji class or whicy modaltype send complexType) my class includes all types
programmerist
@programmerist: Your additional points, and the above comment make no sense whatsoever. Please rephrase.
Jamiec
A: 

From your code it seems that while you could have multiple types you still only do have one at a time, right? If that's the case then Nayan's base-class or Jamiec's interfaces are good options. GenoTipController seems to be a factory and that's exactly what it should do. That way, your clients don't care what the specific type is.

n8wrl
I think he doesn't know about factory. Forget that, he doesn't know what patterns are. Am I wrong? =D He is putting `break` statement after `return` =D
Nayan
Nayan you say; i don't know factory pattern?
programmerist
According to the enum type will produce class.
programmerist