Skip to content

Instantly share code, notes, and snippets.

@trikitrok
trikitrok / wrap-class.md
Created March 14, 2025 10:08
Wrap class

Wrap class.

How to do it:

  1. Identify the change point.

  2. Create a class that accepts the class we are going to wrap as a constructor argument.

    • If we have trouble creating the original class in a test harness, we might have to use Extract Interface on the wrapped class so that we can instantiate the wrapper.
  3. Create a method on the wrapper class with tests, that implements the new behaviour.

@trikitrok
trikitrok / sprout-class.md
Created March 14, 2025 10:02
Sprout class

Sprout class.

How to do it:

  1. Identify the change point and determine the sprouted class interface.

    • Pass to the sprouted class’s constructor any source method’s local variables it needs as parameters.

    • Determine whether the sprouted class’ method will need to return values to the source method.

@trikitrok
trikitrok / wrap-method.md
Created March 14, 2025 10:00
Wrap method

Wrap method.

Version 1 (when clients will only use the composed behaviour).

How to do it:

  1. Identify the change point.

  2. Extract a method with the body of the current method.

@trikitrok
trikitrok / sprout-method.md
Last active March 14, 2025 10:02
Sprout method

Sprout method.

How to do it:

  1. Identify the change point and determine the sprouted method signature (input/output).

    • Pass to the sprouted method any source method’s local variables it needs as parameters.

    • Determine whether the sprouted method will need to return values to any variable in the source method.

<?php
interface Customer {
public function getEarnedDiscount(): float;
public function addToOrdersHistory(Order $order): void;
}
// Null Customer's implementation
class NotFoundCustomer implements Customer {
public interface Customer
{
double GetEarnedDiscount();
void AddToOrdersHistory(Order order);
}
// Null Customer's implementation
public class NotFoundCustomer : Customer
{
public interface Customer {
double getEarnedDiscount();
void addToOrdersHistory(Order order);
}
// Null Customer's implementation
public class NotFoundCustomer implements Customer {
private final double DEFAULT_DISCOUNT = 1.0;
public class Coordinates {
public int x;
public int y;
public Coordinates(int x, int y) {
this.x = x;
this.y = y;
}
}
public class PageSEO {
Page calculate(Page current, Search search) {
// ...
}
}
@trikitrok
trikitrok / IndexationAndCalculator.java
Last active February 4, 2025 17:18 — forked from franreyes/IndexationAndCalculator.java
IndexationAndCalculator.java
public interface IndexationCalculator {
Page update(Page current, Search search);
}
public interface CanonicalCalculator {
Page update(Page current, Search search);
}
public class Page {
public bool isIndexed;