To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Added in 24 Hours
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

Service locator pattern

From Wikipedia, the free encyclopedia


The service locator pattern is a design pattern used in software development to encapsulate the processes involved in obtaining a service with a strong abstraction layer. This pattern uses a central registry known as the "service locator", which on request returns the information necessary to perform a certain task.[1] Proponents of the pattern say the approach simplifies component-based applications where all dependencies are cleanly listed at the beginning of the whole application design, consequently making traditional dependency injection a more complex way of connecting objects. Critics of the pattern argue that it is an anti-pattern which obscures dependencies and makes software harder to test.[2][better source needed]

YouTube Encyclopedic

  • 1/3
    Views:
    2 535
    37 021
    18 422
  • Service Locator Pattern
  • Get_It package - Dependency Injection with Service Locator Pattern in Flutter & Dart
  • Dependency Injection VS Service Locator Pattern

Transcription

Advantages

  • The "service locator" can act as a simple run-time linker. This allows code to be added at run-time without re-compiling the application, and in some cases without having to even restart it.
  • Applications can optimize themselves at run-time by selectively adding and removing items from the service locator. For example, an application can detect that it has a better library for reading JPG images available than the default one, and alter the registry accordingly.
  • Large sections of a library or application can be completely separated. The only link between them becomes the registry.
  • An application may use multiple structured service locators purposed for particular functionality/testing. Service locator does not mandate one single static class per process.
  • The solution may be simpler with service locator (vs. dependency injection) in applications with well-structured component/service design. In these cases, the disadvantages may actually be considered as an advantage (e.g., no need to supply various dependencies to every class and maintain dependency configurations).
  • Service location process can be made sensitive to a calling scope/context which can represent a specific business case. Instead of relying on a fixed DI which typically supplies an object with its dependencies via a constructor parameter passing, the service location call can be made in a business context as needed. For example, you may wish to invoke a "IShippingStrategy" instance obtained via a service location call, supplying a "ShippingContext" as a parameter to service locator stating what is being shipped from where and where to, so service locator can match the best case (e.g. using a pattern match score). This significantly simplifies complex business application architecture (e.g. medical scoring systems, routing) where circuitous decision making can be done via scoring of the best matching strategy located dynamically at a runtime

Disadvantages

  • The registry hides the class' dependencies, causing run-time errors instead of compile-time errors when dependencies are missing (unlike when using constructor injection). But each library is compiled, just the discovery of the concrete Class might not be found and cause an error, it's more a deployment issue than a Service Locator issue.
  • The registry makes code harder to test, since all tests need to interact with the same global service locator class to set the fake dependencies of a class under test. However, this is easily overcome by injecting application classes with a single service locator interface. Simulator can be implemented to simulate each interface provided by the service locator, so it's easy to swap the real implementation with a simulator.

See also

References

  1. ^ Fowler, Martin. "Inversion of Control Containers and the Dependency Injection pattern".
  2. ^ Seemann, Mark. "Service Locator is an Anti-Pattern". blog.ploeh.dk. Retrieved 2017-06-01.

External links


This page was last edited on 15 January 2024, at 20:37
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.