SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Service Locator pattern vs static classes

Last post 12-01-2006 2:02 PM by DanielGrunwald. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-01-2006 1:31 PM

    • boogo
    • Not Ranked
    • Joined on 12-01-2006
    • Posts 2

    Service Locator pattern vs static classes

    Hello.

    I'm reading the great ebook "Dissecting a C# Application" now and when I looked into srierralongue source code I noticed  Workspace Services as static classes instead of Service Locator pattern likes in 1.0 version and ebook desribed.

    Is this because of performance or design issues? Is that good from OOD point of view that static classes have a state of other objects and cast events?

    What about using generic Service Locator http://www.codeproject.com/useritems/GenericServiceLocator.asp
     instead of static classes? 

    Thank you very much .

  • 12-01-2006 2:02 PM In reply to

    Re: Service Locator pattern vs static classes

    Well, static state/events are generally bad; but whether you wrap them in a service object stored in a static hashtable or make them directly static makes no difference. The "store static instances of service interfaces" approach is only useful when there are multiple implementations for the service.

    Really good design would be if every class could get passed a different set of services (a different ServiceLocator instance), but that would be overkill for SharpDevelop - each SharpDevelop process has only one main window, only one solution opened etc.; so static classes make more sense.

    But you should try to prevent calling services/anything static in classes that are not necessarily related to the SharpDevelop main window; for example SharpDevelop AddIns might want to be separated in a SharpDevelop-dependent and an independent part; the SharpDevelop-dependent part would be responsible for getting the current project from the service and passing it to the other part.

    Daniel Grunwald
Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.