Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: A UIKit based Playground for presenting user interface
- import UIKit
- class ContextClass {
- enum Social {
- case vk
- case fb
- }
- func getStrategy(type: Social) -> SocialNetworkStrategy {
- switch type {
- case .vk:
- return VKStrategy()
- case .fb:
- return FBStrategy()
- }
- }
- }
- protocol SocialNetworkStrategy: class {
- func login()
- func logout()
- func sharePost()
- }
- class VKStrategy: SocialNetworkStrategy {
- func login() {
- //do something
- print("vklogin")
- }
- func logout() {
- //do something
- }
- func sharePost() {
- //do something
- }
- }
- class FBStrategy: SocialNetworkStrategy {
- func login() {
- //do something
- print("fblogin")
- }
- func logout() {
- //do something
- }
- func sharePost() {
- //do something
- }
- }
- class GoogleStrategy: SocialNetworkStrategy {
- func login() {
- //do something
- }
- func logout() {
- //do something
- }
- func sharePost() {
- //do something
- }
- }
- // client
- let context = ContextClass()
- let social = context.getStrategy(type: .vk)
- social.login()
Add Comment
Please, Sign In to add comment