Last active
August 31, 2019 20:24
-
-
Save hitendradeveloper/f2f7b3a6eccdc86f5cded45f0c3fc45a to your computer and use it in GitHub Desktop.
Design patterns by Tutorials - The power of OOP (part 3) - Adapter pattern intro example - https://medium.com/p/112a956c1101
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
// Hitendra Solanki | |
// Adapter design pattern Playground example | |
import Foundation | |
class Point { | |
var x: Int | |
var y: Int | |
init(x: Int, y: Int) { | |
self.x = x | |
self.y = y | |
} | |
} | |
class LineSegment { | |
var startPoint: Point | |
var endPoint: Point | |
init(startPoint: Point, endPoint: Point) { | |
self.startPoint = startPoint | |
self.endPoint = endPoint | |
} | |
} | |
//Mark:- DrawingPad | |
// This is just to make example more interesting | |
// We are just printing the point on Console to make it simple | |
class DrawingPad { | |
//Draw Single point, main drawing method | |
func draw(point: Point) { | |
print(".") | |
} | |
//Draw multiple points | |
func draw(points: [Point]) { | |
points.forEach { (point) in | |
self.draw(point: point) | |
} | |
} | |
} | |
func main(){ | |
let drawingPad = DrawingPad() | |
let point1 = Point(x: 10, y: 10) | |
drawingPad.draw(point: point1) | |
} | |
//call main function to execute code | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment