0

I have the following class structure (abbreviated for sake of time, names changed) in my application. When I was writing the code I felt that the similarities between Action1 and Action2 should warrant some sort of generalization. I've provided the UML Class diagram with the relevant parts (except for the interfaces, which I describe in code below). I was wondering if anyone had an idea on how to make this "better" architecture / class design. Also, actions that are very similar could be implemented in a near-future iteration.

UML Diagram http://img16.imageshack.us/img16/2569/mainmm2.jpg

Code for interfaces

public IActor1
{
    public Property1 { get; set; }
    public Property2 { get; set; }
}

public IActor2
{
    public Property3 { get; set; }
    public Property2 { get; set; }
}

2 Answers 2

0

My first look at this came up with the following:

Overload the interface, since both have the interface already implemented. Then, created an Action interface that encapsulates the List, List and ActionType properties of Action1, leaving Action2 to have an empty dummy ActionType property. However, this seems extremely messy and not very extensible (as there are plans for new actions in the future)

0

I'm not sure if this answers your quesion, but here goes.

First, IActor1 and IActor2 should have a common base interface with shared properties:

public interface IActorBase {
    public Property2 { get; set; }
}

Now, the Actions should have a generic base

public abstract class ActionBase<TActor> where TActor: IActorBase {
    public List<String> StringList { get; set; }
    public List<TActor> ActorList  { get; set; }
}

Then, you implement your Action1 and Action2 as such:

public class Action2 : ActionBase<IActor2> { }

public class Action1 : ActionBase<IActor1> {
    public enum Action1Type Type { get; set; }
}

I'm not sure what more you could do here without more details...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.