在UML的类图里,这个一头带个十字圆圈(注意,不是带叉的圆圈)与连线组成的形式,表示内嵌。在实际编程代码中表示嵌在内部的类,通常用来表示突然在内部需要一个匿名类(如new Thread()或者new Runnable()的情况)。
英文介绍如下(摘自
http://www.holub.com/goodies/uml/):
Nesting, Inner Class.. Identifies nesting (containment) relationships in all diagrams. In a class diagram: an "inner" class whose definition is nested within the "outer" class definition. Typically puts the inner class in the name space of the outer class, but may have additional properties.
下面举个例子:
本图所对应的Java代码为:
public class SimpleClass { private Integer num = 3; private Boolean isGood; public Boolean isGoodEnough(Integer goodrange) { return null; } public Integer getNum() { return null; } public class InnerClass { private Integer coolNum; public Integer getCoolNum() { return null; } } } |
对应的C++代码:
#ifndef SIMPLECLASS_H_H #define SIMPLECLASS_H_H class SimpleClass{ public: class InnerClass{ public: Integer getCoolNum( ); private: Integer coolNum; }; Integer getNum( ); Boolean isGoodEnough( Integer goodrange ); private: Boolean isGood; Integer num; }; #endif |
#include "SimpleClass.h" Integer SimpleClass::InnerClass::getCoolNum( ){ } Boolean SimpleClass::isGoodEnough( Integer goodrange ){ } Integer SimpleClass::getNum( ){ } |