Last active
June 1, 2021 01:45
-
-
Save NSLog0/afcbdea23e9b46b857f655083326feff to your computer and use it in GitHub Desktop.
use for article
This file contains 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 INotification | |
def send | |
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'" | |
end | |
def body | |
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'" | |
end | |
end | |
class EmailSender < INotification | |
# override method | |
def send | |
call_email_api(body) | |
end | |
def body | |
return '..... body .....' | |
end | |
end | |
class PushNotiSender < INotification | |
# override method | |
def send | |
call_firebase_api(body) | |
end | |
def body | |
return '..... body .....' | |
end | |
end | |
class SendNotiAdaptor | |
def initialize(type: ) | |
@noti_type = type | |
end | |
def send | |
@adapter = nil | |
case @noti_type | |
when 'email' | |
@adapter = EmailSender.new | |
when 'push' | |
@adapter = PushNotiSender.new | |
else | |
raise ArgumentError, "not provided not type. please choose one of them" | |
end | |
client_caller(@adapter) if !@adapter.nil? | |
end | |
def client_caller(creator) | |
creator.send | |
end | |
end | |
SendNotiAdaptor.new(type: 'email').send | |
SendNotiAdaptor.new(type: 'push').send |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment