I always like to learn from other developer's code; in looking through the Dialogue source, I see there are several "service" classes like Memberservice, TopicService, etc. I am curious what the benefit is for not having them as static classes? They all appear to be stateless, and their methods also appear to be pretty threadsafe.
I'm answering this as not something specific to Dialogue, but a general question of why use a service instead of static classes; Which is a fair question, but not something specific to Umbraco, ASP.NET or for that matter C#.
I thought best to give you a few links to look at:-
My general rule for static classes is only use them when you have to, not because you can. If you were to chart the progression of computer programming over the last 30 years, the aim to reduce global and static content has been never ending and more inventive approaches have been deployed to achieve this. Singletons for example.
On a practical note, many/most/99% use static classes on helper classes, feel free to debate freely on the pros and cons of such behaviour - great, a necessary evil or pedantic mussing.
Design Question ( *Service classes)
I always like to learn from other developer's code; in looking through the Dialogue source, I see there are several "service" classes like Memberservice, TopicService, etc. I am curious what the benefit is for not having them as static classes? They all appear to be stateless, and their methods also appear to be pretty threadsafe.
Hi John,
I'm answering this as not something specific to Dialogue, but a general question of why use a service instead of static classes; Which is a fair question, but not something specific to Umbraco, ASP.NET or for that matter C#.
I thought best to give you a few links to look at:-
https://en.wikipedia.org/wiki/Servicelayerpattern
https://stackoverflow.com/questions/13769976/design-patterns-service-layer
https://stackoverflow.com/questions/31180816/mvc-design-pattern-service-layer-purpose
My general rule for static classes is only use them when you have to, not because you can. If you were to chart the progression of computer programming over the last 30 years, the aim to reduce global and static content has been never ending and more inventive approaches have been deployed to achieve this. Singletons for example.
On a practical note, many/most/99% use static classes on helper classes, feel free to debate freely on the pros and cons of such behaviour - great, a necessary evil or pedantic mussing.
Cheers
Jonathan
is working on a reply...