UML generalization and realization

限于喜欢 提交于 2019-12-01 17:44:54
xmojmr

In your opinion which of the two descriptions is better?

In my opinion option 3 sketched in the picture below is better. Timer would be reusable (conceptually final) universal class, it's instance only configured by the singleton wrappers and linked by usage dependency relationship

VP allows to write implementation code for the three operations. During code generation...Is it correct to write code implementation for the operations of an interface...?

I don't know how to correctly configure Visual Paradigm's code generator to produce what you want, but although C++ interface is just a class like any other and there's no special keyword for this concept, UML interface is meant to be only description of a contract with no coupled implementation. Some languages like C# or Java have special interface keyword for this purpose, with no-code rule hardcoded in the compiler.

Thus, although Visual Paradigm can perhaps generate the code which you want at the end, from UML perspective, modeling an interface with code is wrong


Make your choice. If you want just code that does The something, then go and hack it anyway which works (as @gilead-silvanas suggests). If you want to practice UML for use in your future projects using different languages, then don't.

Also there's a time when the initial generated code will depart from the initial design drawings and from the code generator and you'll edit it by hand, even if you'd use a tool like Quantum Leaps Modeler for embedded systems.

I'd reconsider (regularly) if fighting with the design tool over-weights the code generation benefits

Probably this is just a shorthand for VP to make things quicker. As you said, upon code generation, it clears those codes anyway from the interface and put it in the realizing classes. I don't see anything wrong with that because what matters is the generated code, which in your case is correct.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!