vendredi 15 mai 2015

Call same code for two Sublasses

I have three Classes Base::Builder, Base::Builder::Carand Base::Builder::House

Lets suppose I have this code that I want to shorten:

Base::Builder::Car
  .new(@build_plan)
  .generate

Base::Builder::House
  .new(@build_plan)
  .generate

What I did was:

 [Base::Builder::Car, Base::Builder::House].each do |builder|
   builder.new(@build_plan)
          .generate 
 end

But I dont really like this refactoring, because like this, It gets unreadable

How would you Refactor this Code? Thanks!

Aucun commentaire:

Enregistrer un commentaire