Created
May 11, 2021 16:39
-
-
Save armandofox/a100b89babb3e1dfc3f0fbbe98fcd820 to your computer and use it in GitHub Desktop.
srp_example.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Moviegoer | |
attr_accessor :name, :street, :phone_number, :zipcode | |
validates :phone_number, # ... | |
validates :zipcode, # ... | |
def format_phone_number ; ... ; end | |
def check_zipcode ; ... ; end | |
def format_address(street, phone_number, zipcode) # data clump | |
# do formatting, calling format_phone_number and check_zipcode | |
end | |
end | |
# After applying Extract Class: | |
class Moviegoer | |
attr_accessor :name | |
has_one :address | |
end | |
class Address | |
belongs_to :moviegoer | |
attr_accessor :phone_number, :zipcode | |
validates :phone_number, # ... | |
validates :zipcode, # ... | |
def format_address ; ... ; end # no arguments - operates on 'self' | |
private # no need to expose these now: | |
def format_phone_number ; ... ; end | |
def check_zipcode ; ... ; end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment