Strangler fig pattern

In programming, the strangler fig pattern or strangler pattern is an architectural pattern that involves wrapping old code, with the intent of redirecting it to newer code or to log uses of the old code. Coined by Martin Fowler,[1] its name derives from the strangler fig plant, which tends to grow on trees and eventually kill them. It has also been called Ship of Theseus pattern, named after a philosophical paradox.[2]

The pattern can be used at the method level or the class level.[3]

Rewrites

One use of this pattern is during software rewrites. Code can be divided into many small sections, wrapped with the strangler fig pattern, then that section of old code can be swapped out with new code before moving on to the next section. This is less risky and more incremental than swapping out the entire piece of software.[1]

The strangler fig pattern can be used on monolithic applications to migrate them to a microservices architecture.[1][4]

Logging

Another use of this pattern is the addition of logging to old code. For example, logging can be used to see how frequently the code is used in production, which can be used to decide whether to delete low-usage code, or to rewrite high-usage code.[5]

See also

References

  1. ^ a b c Newman, Sam (2020). Monolith to Microservices: Evolutionary Patterns to Transform Your Monolith. O'Reilly Media. pp. 79–97. ISBN 978-1-492-07554-7.
  2. ^ Carlo, Nicolas. "The Ship of Theseus to NOT rewrite a legacy system from scratch". Understand Legacy Code.
  3. ^ Seemann, Mark (2022). Code That Fits in Your Head: Heuristics for Software Engineering. Addison-Wesley. pp. 228–237. ISBN 978-0-13-746440-1.
  4. ^ Behara, Samir (12 December 2018). "Monolith to Microservices With the Strangler Pattern". DZone. Retrieved 12 March 2024.
  5. ^ Clausen, Christian (2021). Five Lines of Code: How and when to refactor. Manning Publications. pp. 206–208. ISBN 9781617298318.

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.