问题描述
大家好,
我试图在Code Project上寻找解决方案,但没有找到解决方案.因此,如果以前曾问过这个问题,请指出正确的方向.
好的,所以我试图在VS2010中使用C#实现复合设计模式结构.
首先,我使用的设计模式并不重要,但是我很好奇的是VS2010及其从我的结构生成的类图.
我创建了一个抽象的Component类,并让Composite类从中继承.我还具有从抽象的Component Class继承的Leaf Class.
为了在Component和Composite之间进行简单的聚合,可以使用ArrayList,但是我选择了通用列表.组件
.因此,现在我可以使用
public void addChild(Component childComponent)
将子级添加到我的Composite中.这有效并且很酷.但是我注意到(在VS2010中生成类图时),没有箭头(聚集)从Composite指向我的组件类.通过使用
List<Component> component
确实存在聚合.
然后,如果我继续并绘制从Composite到Component的聚合,则会在我的Composite类中生成以下代码:
public 组件组件 { 获取 { 抛出 新 System.NotImplementedException(); } 设置 { } }
所以,最后是我的问题:您如何将生成的代码与List< t>一起使用.甚至有必要为此担心吗?
Hi all,
I tried to look for a solution on this on Code Project, but found none. So if this question has been asked before, please point me in the right direction.
Ok, so I am trying to implement a Composite Design Pattern structure using C# in VS2010.
Firstly, what I''m using the design pattern for is not important, but what I am curious about is VS2010 an its Class Diagrams that it generate from my structure.
I created an abstract Component Class and have the Composite Class inheriting from that. I also have the Leaf Class inheriting from the abstract Component Class.
For a simple aggregation between Component and Composite, one can use an ArrayList, but I opted for a generic list
List<Component> component
. So now I can use a method
public void addChild(Component childComponent)
to add children to my Composite. This works and is cool. But I noticed (when generating a class diagram in VS2010) that there is no arrow (aggregation) pointing to my Component Class from Composite. An aggregation does exist through the use of my
List<Component> component
.
If I then continue and draw an aggregation from Composite to Component, the following code is generated in my Composite Class:
public Component Component { get { throw new System.NotImplementedException(); } set { } }
So, finally my question: How would you use this generated code with a List<t>. Is it even necessary to worry about this?
Thanks in advance.
这篇关于使用通用列表作为属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!