C# .NET Core example

94 views
Skip to first unread message

Alexej Sommer

unread,
Feb 27, 2020, 12:16:42 AM2/27/20
to object-composition
Hi folks!

I have ported Java example to .NET Core. You can find it on github
If you have any related comments I will be glad to listening for.

Have also 2 questions:

Do we need obligatorily to use reflection for decoupling? I mean does reflection is a part of DCI concept? Was able to find some sentences about it.

How can I find example of usage with MVC? What is a profit of combination?

Egon Elbre

unread,
Feb 27, 2020, 2:23:06 AM2/27/20
to object-composition
On Thursday, 27 February 2020 07:16:42 UTC+2, Alexej Sommer wrote:
Hi folks!

I have ported Java example to .NET Core. You can find it on github
If you have any related comments I will be glad to listening for.

Have also 2 questions:

Do we need obligatorily to use reflection for decoupling? I mean does reflection is a part of DCI concept? Was able to find some sentences about it.

Reflection is an implementation detail. In a similar way how you can implement Classes internally different ways, so you can also implement DCI in different ways.

If you wish to see whether everything is behaving as it should you can take a look at this torture scenario:

You can read these for more about the torture test and discussion around it:

Looking over your code, few ideas:
* you can try moving Source and Destination private classes inside Context class to make it slightly clearer. Roles only make sense in a Context.
* Rename your "Context" class to something meaningful. You don't call all your classes "Class", hopefully. :)

Based on the code the implementation seems right, although, the custom calling convention for calling methods is confusing and probably won't give you the right feel for DCI. In a similar way confusing if you were to try to write class oriented code in C.


How can I find example of usage with MVC? What is a profit of combination?


Before continuing you would need to clarify what you mean by MVC, since the term is being used in too many ways.

+ Egon

Rune Lund-Søltoft

unread,
Feb 27, 2020, 3:49:47 AM2/27/20
to object-co...@googlegroups.com
Three comments

Try to implement the dijkstra example from fulloo.info

The role method is supposed to be a member of the object and not a member of another object. Ie "this" inside the role method points to the roleplayer not the context

Try and create a syntax that shows that the role-method is an instance method of the roleplayer and not more like a procedure that takes the name of the role as an argument

Best regards
Rune

--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to object-composit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/object-composition/66cf778e-9c42-46d1-a7e1-68b3573c5f64%40googlegroups.com.

Alexej Sommer

unread,
Feb 27, 2020, 3:06:32 PM2/27/20
to object-composition
Thank you for recommendations guys,
In C# I can't  access private classes inside parent class in the way like it could be done in Java. That's why I have moved them away.
When classes are away the code is more readable, but i agree that sample would be more clear if move classes into context. Thanks again.

Andreas Söderlund

unread,
Feb 27, 2020, 4:00:35 PM2/27/20
to object-composition
Hi Alexej, I've gone through most of the pains in a C# implementation 7 years ago. (time flies!) My conclusion is that even when using internal classes, making a single .cs-file similar to a Context in scope, the code gets verbose and it's a nuisance accessing the context from the extension methods, as I used for roles to make the syntax nicer.


It's quite obvious which one is more readable, and readability is a definite goal of DCI.

Best regards,
Andreas
Reply all
Reply to author
Forward
0 new messages