简体   繁体   English

在类图中表示main()

[英]Representing main() in a class diagram

I'm constructing a simple class diagram for a class assignment and I was wondering how I should go about incorporating functions defined and declared in main() (it's for a C++ project) into it. 我正在为类分配构建一个简单的类图,并且想知道如何将main()中定义和声明的函数(用于C ++项目)整合到其中。 These functions don't fit into any of the classes that I have, and since there aren't any variables that accompany them, it seems pointless to create a control class containing only a few functions with no data. 这些函数不适合我拥有的任何类,并且由于它们没有任何变量,因此创建仅包含少量无数据的函数的控件类似乎毫无意义。 Aside from keeping things neat, I'm concerned about it from a code generation point of view - if I simply create a class called main() , I'll get only called just that, rather than the functions being declared within the main() function. 除了保持整洁之外,我还从代码生成的角度来关注它-如果我仅创建一个名为main()的类,则只会调用该类,而不是在main()声明的函数main()功能。

FWIW, I'm using Enterprise Architect to model the code. FWIW,我正在使用Enterprise Architect建模代码。

class diagram doesn't need to depict every detail. 类图不需要描述每个细节。 C++ is a multiparadigm language, so not everything is an object. C ++是一种多范式语言,因此并非所有事物都是对象。 you need to show only those details that can be well represented on class diagram and that will help to understand the system better. 您只需要显示可以在类关系图上很好地表示并且有助于更好地理解系统的那些细节。 your functions can be represented on control flow diagram or even not represented at all if they aren't so important. 您的功能可以在控制流程图中表示,或者如果不那么重要,甚至可以根本不表示。

It's not as pointless as you may think -- that's why languages such as Java mandate that everything goes into a class. 这并非没有您想像的那么重要-这就是为什么Java之类的语言要求将所有内容都归为一类的原因。 If you're following a strict OOP design, put everything into classes and just have your main function instantiate your main application class. 如果您遵循严格的OOP设计,则将所有内容放入类中,而仅让您的main函数实例化您的主应用程序类。 For the kind of functions that you describe, you could make them static methods of one or more "helper" or "utility" classes. 对于您描述的功能类型,可以使它们成为一个或多个“帮助程序”或“实用程序”类的静态方法。

The aim of modeling is "understanding" complex problems and share this undestanding with others to solve difficult problems. 建模的目的是“理解”复杂的问题,并与其他人共享这种不理解的问题以解决难题。

In that situation, UML does not seem to help you... So be pragmatic. 在这种情况下,UML似乎对您没有帮助...所以务实。 Use other notations( may be flow chart...)... Who will use your model? 使用其他符号(可能是流程图...)...谁将使用您的模型? If there is no specific answer, do not model anyting. 如果没有具体答案,请不要建模。 If you has concrete answer, ask yourself how can i help model users? 如果您有具体的答案,请问自己如何为用户建模? What they expect from me... 他们对我的期望...

If uml does not fit your problem do not use it... 如果uml不适合您的问题,请不要使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM