Replace Type Code with Module Extension

You have a type code that affects the behavior of a class.

Replace the type code with dynamic module extension.

class MountainBike…
  def price
    case  type_code 
      when :rigid
        (1 + @commission) * @base_price
      when :front_suspension
        (1 + @commission) * @base_price + @front_suspension_price
      when :full_suspension
        (1 + @commission) * @base_price + @front_suspension_price + 
      @rear_suspension_price
    end
  end 
    

image/svg+xml

module FrontSuspensionMountainBike…
   def price
     (1 + @commission) * @base_price + @front_suspension_price
   end

class MountainBike…
  def type_code=(mod)
    extend(mod)
  end