title @price = price @author = author end def display_info puts "#{@title}: ¥#{@price}" end end class CD def initialize(title, price, artist) @title = title @price = price @artist = artist end def display_info puts "#{@title}: ¥#{@price}" end end title price display_info が クラスごとに重複 共通部分を Product に集約 class Product def initialize(title, price) @title = title @price = price end def display_info puts "#{@title}: ¥#{@price}" end end class Book < Product def initialize(title, price, author) super(title, price) @author = author end end # CD < Product も同様 共通仕様の変更は Product 1箇所で済む 『オブジェクト指向でなぜつくるのか』中間アウトプット 服部潤一 11