I had some classes like this:
+---+ +---+
| L | ---uses---> | D |
+---+ +---+
| +---+
inherit ----<---- | V |
| +---+ +---+
+---<--- | C |
+---+
Let's say; class L is an abstract class, and V and C inherits from it. And L have a property of class D. - sorry for my bad drawing and also English-
Now, I need to add a new class -RA- that has a property of class D and class V should have a property of class RA, But I also need to get property from objects of class L So V. In my mind something like this:
+---+ +---+ +----+
| L | --uses--> | D | <--uses-- | RA |
+---+ +---+ +----+
| +---+ |
inherit ----<----| V | --uses-->--+
| +---+ +---+
+---<---| C |
+---+
I'm not sure!; But it seems to me like an anti-pattern or breaker of LSP -of SOLID principle- somehow!, But I can't figure it out.
Is my new diagram an anti-pattern? or is there a better way to design this situation?
Note that classes like D, V, C and RA can instantiate.
And I meant that usage of property of class D is now hierarchically in class V.
Edit:
Imagine that I use an interface -IGFP- that returned a string value by using D property in L so in V and C, now in V I need to override it by using RA instead of D.
In C# classes are:
public abstract class L : VOBase<L>, IGFP {
public virtual D D { get; protected set; }
public virtual string Name { get; protected set; }
public virtual string GFP => $"{D.GFP}/{Name}"; // Here I use D property that I think breaks LSP
}
public class C : L {
public C (D d, string name) {
D = d;
Name = name;
}
}
public class V : L {
public V (RA ra, string name) {
RA = ra;
Name = name;
D = ra.D;
}
public RA RA { get; private set; }
public override string GFP => $"{RA.GFP}/{Name}"; // Here I should override GFP to use RA instead of D
}
public class D : VOBase<D>, IGFP {
public D (U u, string name) {
U = u;
Name = name;
}
public U U { get; private set; }
public string Name { get; private set; }
public string GFP => $"{U.GFP}/{Name}";
}
public class RA : VOBase<RA>, IGFP {
public RA (D d, string name) {
D = d;
Name = name;
}
public D D { get; private set; }
public string Name { get; private set; }
public string GFP => $"{D.GFP}/{Name}";
}