Skip to content

Instantly share code, notes, and snippets.

@iamcrypticcoder
Created March 30, 2018 19:08
Show Gist options
  • Save iamcrypticcoder/b37d7828e1d85001a88a4235d469ba87 to your computer and use it in GitHub Desktop.
Save iamcrypticcoder/b37d7828e1d85001a88a4235d469ba87 to your computer and use it in GitHub Desktop.
import Foundation
public class Shape {
let graphicsApi: GraphicsAPI
init(_ graphicsApi: GraphicsAPI) {
self.graphicsApi = graphicsApi
}
func draw() -> Void {
}
}
public class Circle : Shape {
var x: Int = 0
var y: Int = 0
var radius: Int = 0
convenience init(_ x: Int, _ y: Int, _ radius: Int, _ graphicsApi: GraphicsAPI) {
self.init(graphicsApi)
self.x = x
self.y = y
self.radius = radius
}
override func draw() -> Void {
self.graphicsApi.drawCircle(self.x, self.y, self.radius)
}
}
public class Rectangle : Shape {
var x: Int = 0
var y: Int = 0
var width: Int = 0
var height: Int = 0
convenience init(_ x: Int, _ y: Int, _ width: Int, _ height: Int, _ graphicsApi: GraphicsAPI) {
self.init(graphicsApi)
self.x = x
self.y = y
self.width = width
self.height = height
}
override func draw() -> Void {
self.graphicsApi.drawRectangle(x, y, width, height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment