.NET抽象类。 [英] .NET abstract classes.

查看:127
本文介绍了.NET抽象类。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个网站导航层次结构。这是一个节点树。

I'm designing a web site navigation hierarchy. It's a tree of nodes.

大多数节点页面。一些节点的链接(在Windows思快捷方式)。

Most nodes are pages. Some nodes are links (think shortcuts in Windows).

大多数页面容纳HTML内容。一些执行code。

Most pages hold HTML content. Some execute code.

我想重新present这些作为类和抽象(为MustInherit)类&hellip这个集合;

I'd like to represent these as this collection of classes and abstract (MustInherit) classes…

这是数据库中的表,我要去哪里存储此与所有hellip;

This is the database table where I'm going to store all this…

在此处,我难倒。 PageNodes可能或可能不是根

Here's where I'm stumped. PageNodes may or may not be roots.

我应该如何处理根类?

我不希望必须具备全部四项…

I don't want to have to have all four of…

  • HtmlPageNode
  • codePageNode
  • 的Html **根** PageNode
  • code ** **根PageNode

我想HtmlPageNode和codePageNode类继承的或者的从PageNode否则,从RootPageNode。这可能吗?

I want the HtmlPageNode and CodePageNode classes to inherit either from PageNode or else from RootPageNode. Is that possible?


澄清:有多个根节点和根部可有父节点。每个是仅一子树具有不同造型的根。想想不同,color- codeD部门。 (也许根本就是一个可怜的名字的选择。建议?)

Clarification: There are multiple root nodes and roots may have parent nodes. Each is the root of only a sub-tree that has distinct styling. Think of different, color-coded departments. (Perhaps root is a poor name choice. Suggestions?)


更新:关于根的名字......
我问:<一href="http://stackoverflow.com/questions/86790/is-there-a-specific-name-for-the-node-that-coresponds-to-a-subtree">Is那里的coresponds一个子树的节点,特定的名称?

Update: Regarding the "Root" name...
I've asked: Is there a specific name for the node that coresponds to a subtree?

推荐答案

使用的组合模式


对于你的根结点,有没有在功能上的差异或区别是完全的外观?如果不同的是外观上唯一的,我建议你从你的PageNode有一个单独的样式类的关联。

With regard to your root nodes, are there differences in functionality or is the difference it entirely appearance? If the difference is appearance only I suggest you have an association with a separate Style class from your PageNode.

如果在功能上有分歧,你有很多类型的页面再想想使用修饰模式

If there are differences in functionality AND you have lots of types of page then think about using the Decorator Pattern.

这篇关于.NET抽象类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆