let objEmp = Employee(httpHandler: HttpHandler(), parser: Parser(), databaseHandler: DatabaseHandler())
### 2. Open/Closed Principle (OCP):
2. **Open/Closed Principle (OCP):** Software entities (classes, modules, functions, etc.) should be open for
extension but closed for modification. You can add new features without changing existing code.
Example: Extensible Logging System
protocol Shape {
func calculateArea() -> Double
}
class Circle: Shape {
let radius: Double
init(radius: Double) {
self.radius = radius
}
func calculateArea() -> Double {
return Double.pi * radius * radius
}
}
class Triangle: Shape {
let base: Double
let height: Double
init(base: Double, height: Double) {
self.base = base
self.height = height
}
func calculateArea() -> Double {
return 1/2 * base * height
}
class Rectangle: Shape {
let width: Double
let height: Double
init(width: Double, height: Double) {
self.width = width
self.height = height
}
func calculateArea() -> Double {
return width * height
}
}
class AreaCalculator {
func area(shape: Shape) -> Double {
return shape.calculateArea()