Implement same domain model in Python and C# - What should be the same and what should vary?

166 Views Asked by At

I am, as a hobby and best-practice exercise, to implement the same domain model (a simple GPS / GIS library, inspired in ISO 191xx stardards and OGC Abstract Model) both in Python and C#.

It first, I tought: "well, ISO/OGC gave me a finished UML, so I will have each class in C# and in Python to have the same signature".

I quickly found myself stuck in the "strict/static vs duck typing" problem, since I cannot count on method signatures in python. For example:

  • Overloading constructors is quite common and natural in C#, but in Python you have to resort to *args **kwargs and conditionals;
  • Properties are encouraged in C#, but most source code I have seen around in Python tend to set the fields directly, although the use of @property or property() is quite straightforward.
  • (and so on).

Actually there is (obviously) an obvious and very well documented "difference in mindsets" between one language and the other, and I would like to respect those differences while at the same time ending up with "the same" application, that is, equivalent domain model, architecture and functionality.

So my question basically is:

If I am to implement the same abstract model ("UML-like") in Python and C#, how should I proceed, and specifically, which constructs should be invariant, and which should be different?

1

There are 1 best solutions below

0
On

What you called "abstract model" in MDA is called Platform Independent Model (PIM), and its implementation in C# and/or Python is called Platform Specific Model (PSM). It is supposed that there exist tranformations/code-generators from PIM to PSM's, so depending on how these code-generations work you will get appropriate C# and Python source code. Usually, such tools provide some means to control the code generated. And such control usually done via PIM annotations which are specific to PSM you are generating. Hope this helps.