![](/img/trans.png)
[英]C# - How to make a method only visible to classes that inherit the base class of the method
[英]C# Is it worth to create abstract class with only one method and are this classes enough related to each other to inherit form one base class?
我正在做 WPF 應用程序,我將在其中創建 3 個或更多類似的類。 每個 class 將僅使用抽象 class 中的此方法:
abstract class StackPanelBase
{
protected StackPanel CreateStackPanel(Orientation orientation)
{
StackPanel sp = new StackPanel();
sp.Orientation = orientation;
return sp;
}
}
從基礎 class 繼承的類是 StackPanel 中用於不同事物的內容的變體。 一個將用於這樣的事情:
從同一個基礎 class 繼承是否足夠相互關聯,並且為它創建基礎 class 是否值得?
當前編寫的基礎 class 提供零值,並引入了不必要的復雜性。 基礎 class 只是簡單地抽象出StackPanel
的 s.ctor。 這是沒有意義的。
由於這是 WPF,因此在 model 中為Orientation
創建一個屬性,然后將其綁定到 xaml 中的StackPanel
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.