# Refactoring

Tactical services introduce higher than necessary coupling between service providers and consumers and have brittle contracts that forcing service implementation changes on consumers. They do not reuse standard schemas and datatypes increasing data transformation and integration costs and could tightly couple service business logic and transport-specific logic.

![](https://554308880-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M582UGYGD2c_w9yDn9h%2F-M582WQ-8b_WXXwU287f%2F-M582fILiiY5nkBrxu3J%2Frefactoring.jpg?generation=1587142378408041\&alt=media)

Tactical components or services inhibit reusability, increase maintenance costs and reduce the overall effectiveness. So, why do teams do this? Here are five reasons:

1. _Lack of time to design proper service interfaces_ – service contracts are rushed to clients exposing needless internal details, introducing redundant business object definitions, and providing inconsistent behavior
2. _Lack of a conceptual data model_ – if there isn’t a conceptual data model, capturing key domain concepts and their relationships – it is natural that multiple service operations start to define concepts in their unique way.
3. _Insufficient coordination between teams building service capabilities within the domain_ – when teams don’t talk to each other, many opportunities to reuse schemas, service semantics, behavior, and utilities are lost. As the number of teams increase, there is a greater need for service governance and alignment across projects.
4. \_Lack of coherent strategy tying business process management, business events, and messaging - \_within the context of service development. Business processes could be service enabled and standard business schemas can be used to notify interested consumers. However,without an overall strategy – teams will look at these independently thereby increasing implementation costs and missing opportunities for greater alignment.
5. _Insufficient technical leadership_ – when confronting multiple projects that are either occurring within a short time window or back to back, it is critical to demonstrate leadership. Why? there needs to be strong voice evangelizing use of business facing services, loosely coupled interfaces, and [mediating service requests](mediate-service-requests-and-responses).

The Service Refactoring pattern facilitates changes in service logic and/or underlying service implementation while preserving existing consumer contracts.

The [Service Refactoring pattern](http://www.soapatterns.org/service_refactoring.asp) allows the service provider to change the service implementation while preserving existing service contracts. This allows the provider the flexibility to honor existing consumers while taking advantage of streamlined service logic and/or better technologies. If this idea sounds familiar, it is based on the refactoring principles and techniques advocated by Martin Fowler in the object oriented design paradigm and aims to achieve the same result for services. This pattern requires the development of an adapter – that will translate messages conforming to the existing contract into the refactored contract and vice versa.

This pattern:

* Allows for phased migration of consumers who use existing contract to a new one
* Allows the provider to upgrade/enhance service behavior in phases. The refactoring can be accomplished via multiple steps and don’t all have to be bundled in a single release
* Eliminates the need for consumers to change code to take advantage of refactored service
* Allows new consumers to bind to the enhanced service contract and allows for new and existing consumers to co-exist
* Potentially enhance performance, availability, and scalability as new consumers come on board

There is a need for strong and coordinated service governance to make sure that consumers are aware of the refactoring effort, retest to validate the behavior, and ultimately provide sign-off for the service capability to be turned on in a production environment. At a minimum, this pattern needs to make sure that existing consumers conduct regression testing to guarantee that the refactored service doesn’t necessitate code changes.
