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

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

问题描述

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



大多数节点是页面。有些节点是链接(在Windows中为快捷键)。



大多数页面都包含HTML内容。一些执行代码。



我想将它们表示为此类类和抽象(必须继承)的类…





这是数据库我要在其中存储所有表格的表…



解决方案

使用复合模式






关于您的根节点,功能上是否存在差异,还是外观完全不同?如果只是外观上的差异,我建议您与PageNode上的单独的Style类有关联。



如果功能上有差异并且页面类型很多然后考虑使用装饰器模式


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

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

Most pages hold HTML content. Some execute code.

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

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

database table http://img178.imageshack.us/img178/8573/nodetablefm8.gif

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

How should I handle the root class?

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

  • HtmlPageNode
  • CodePageNode
  • HtmlRootPageNode
  • CodeRootPageNode

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


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?)


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

解决方案

Use the the Composite Pattern.


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天全站免登陆