Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Bergman 483 posts 1132 karma points
    May 23, 2017 @ 04:57
    John Bergman
    0

    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.

  • Jonathan Richards 288 posts 1742 karma points MVP
    May 26, 2017 @ 11:20
    Jonathan Richards
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft