Replies: 2 comments 1 reply
-
As I replied in dotnet/csharplang#8075 and other threads, there's no direct support for compositing types with method-sets. Using default interface methods is a workaround, but you do need to know the difference and pay attention to interface methods. As explained in #106916, there are three key differences when declaring methods inside interface context: they are |
Beta Was this translation helpful? Give feedback.
-
@huoyaoyuan, thank you for the explanation both here and in the issue. However, in this question, I'm trying to seek help for designing this BCL. What options do I have to make this library as clean as possible for the end users?
What options do I have? |
Beta Was this translation helpful? Give feedback.
-
I reported my problem as an issue: #106916
I want to create a migration BCL (base class library). The migration BCL should be clean and have as little boilerplate code as possible.
It is expected for users to create classes, inherit from
Migrator
, and have access to all methods related to the database:As you can see, there are many methods. This makes the
Migrator.cs
a God object. So we intend to break it into meaningful packages (maybe Interface Segregation Principle):So we divide a file with thousands of lines into multiple files, each with fewer than a thousand lines and each about a specific database object.
Yet, we end up with a new problem. How to join them back in the
Migrator
class? We don't have multiple inheritance in C#. We don't have mixin, we don't have traits.So, one possible solution could be that we change them all into interfaces, and then use the default interface methods:
But then we end up with this problem that second-level inheritors won't be able to access these default methods:
The
HasColumn
is not accessbile in theUserMigrator
class.And if we try to explicitly implement each method in the
Migrator
class:We end up with stack overflow.
If we try to use DI, then we won't be boilerplate-free:
A lot of boilerplate, with no value in this context.
What architecture would solve this problem? If C# had a simple mixin or trait syntax, we would do it this way:
Beta Was this translation helpful? Give feedback.
All reactions