Steven Du
Steven Du

Reputation: 1691

How to architect this kind of project?

To say I have two classes:

 ClassA{
    //properties 
    public string NAME{set;get;}
    public string ID{set;get;}
    public int AGE{set;get;}
    //Methods
    public void DoSomething();
    public void MethodA();
    private void MethodB(string name);
    private void MethodC(string name);
    public void MethodD(string name,string id);
    public string getSomething(int age);
    }

    ClassB{
    public void Hello(int input);
    public void HelloWorld(string input);
    }

1) For ClassA(may have many derived classes),what is the best way to create a design interface(GUI) so that I can specify its property value

2) For ClassA, is there a way to create a design interface(GUI) so that I can specify which method to call and specify the sequence/input/output of methods called?

    public void DoSomethingWithClassA(ClassA ca ){
    ca.MethodA();
  //  ca.MethodB(ca.NAME);
  //  ca.MethodB(ca.ID);
    ca.MethodD(ca.NAME,getSomthing(ca.AGE));

    }

3) If I have an instance of ClassA, named newClassA, an instance of ClassB, named newClassB, is there a way to create a design interface(GUI) so that I can specify that newClassB could invoke newClassA's method:

ClassA newClassA...
ClassB newClassB...

newClassB.HelloWorld(newClassA.getSomething(newClassA.AGE));

Basically what I need is to have a design interface(GUI) so that user could "visually design" his classes and could specify relation/input/output of method. I feel it's something like filter graph.

If someone could possible figure out a solution/framework/design pattern/keywords, it would be much appreciated.

(I should highlight that design interface means GUI for user, sorry for that.)

Upvotes: 2

Views: 165

Answers (1)

Guillaume
Guillaume

Reputation: 1802

I think you are looking for something like fluent interfaces.

Take a look at this article, it should help you on how to implement this: http://blog.raffaeu.com/archive/2010/06/26/how-to-write-fluent-interface-with-c-and-lambda.aspx

Here's a quick example on how you can use this:

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }

    internal Person { }
}

public class PersonFactory
{
    public NameSetter CreatePerson()
    {
        return new NameSetter(new Person());
    }
}

public class NameSetter
{
    private Person person;

    internal NameSetter(Person person)
    {
        this.person = person;
    }

    public AgeSetter SetName(string name)
    {
        this.person.Name = name;
        return new AgeSetter(this.person);
    }
}

public class AgeSetter
{
    private Person person;

    internal AgeSetter(Person person)
    {
        this.person = person;
    }

    public Person SetAge(int age)
    {
        this.person.Age = age;
        return this.person;
    }
}

public class Program
{
    public void Main()
    {
        Person p = new PersonFactory()
                       .CreatePerson()
                       .SetName("Bob")
                       .SetAge(30);
    }
}

I updated the example to make the constructor of Person internal. It's not mandatory but if you do so, it will force any user of your code to use the fluent interface to create an instance of a Person.

Upvotes: 4

Related Questions