lundi 5 novembre 2018

C# override property with child/parent relationship

So basically what I want to be able to do is to be able to a single property name space that can be overridden by a child of that property's parent. The practical application here is maintaining a Model/View system. Where the views are derived from the same base view class, however some require a more complex model to perform their function.

I was wondering if there is a best practice pattern for this since my current approach of just hiding variable namespaces seems too messy. Here's some sample pseudo-code of what I mean:

public class ParentPropertyType{

public string bar = "bar";

}

public class ChildPropertyType: ParentPropertyType{

public string foo = "foo";

}


public class ChildManager:ParentManager {

public virtual ChildPropertyType PropertyType {get; set;}

}

public class ParentManager{

public override ParentPropertyType PropertyType {get; set;}

}

...

Debug.Log(new ParentManager().PropertyType.foo);

Aucun commentaire:

Enregistrer un commentaire