Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Plataformatec Hack Evening: SOLID Series - Inte...

Avatar for Lucas Santos Lucas Santos
September 25, 2018

Plataformatec Hack Evening: SOLID Series - Interface Segregation Principle

In this presentation, we will understand how the Interface Segregation Principle can be used to reduce the interface fatness.

Avatar for Lucas Santos

Lucas Santos

September 25, 2018
Tweet

More Decks by Lucas Santos

Other Decks in Programming

Transcript

  1. • "Clients should not be forced to depend on methods

    that they don’t use” 
 -Robert C. Martin; Prentice Hall, 2003
  2. class UserRepository def get_all_by_ids(ids) @entity.where(id: ids) end private def entity

    User end end class UserController def index UserRepository.new.get_all_by_ids(params[ids]) end end
  3. class UserRepository def get_all_by_ids(ids, sort) users = @entity.where(ids: ids) if

    sort users.order(created_at: :asc) end users end private def entity User end end class UserController def index UserRepository.new.get_all_by_ids(params[ids]) end end
  4. class UserRepository def get_all_by_ids(ids) @entity.where(ids: ids) end def get_all_by_ids_sorted(ids) get_all_by_ids.order(created_at:

    :asc) end private def entity User end end class UserController def index UserRepository.new.get_all_by_id_sorted(params[ids]) end end