Skip to content

Instantly share code, notes, and snippets.

@hitendradeveloper
Last active August 31, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitendradeveloper/f2f7b3a6eccdc86f5cded45f0c3fc45a to your computer and use it in GitHub Desktop.
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
// 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