0% found this document useful (0 votes)
9 views1 page

Solid ISP Swift

Uploaded by

Amazing Deals
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Solid ISP Swift

Uploaded by

Amazing Deals
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

}

class Square: Shape {


var side: Double

init(side: Double) {
self.side = side
}

var area: Double {


return side * side
}
}
```

### 4. Interface Segregation Principle (ISP):


4. **Interface Segregation Principle (ISP):** A class should not be forced to implement interfaces it does not
use. Clients should not be forced to depend on interfaces they do not use.

Example: Breaking Down a Monolithic Protocol

```swift
// Not following ISP
protocol Worker {
func work()
func takeBreak()
func attendMeeting()
}

// Following ISP
protocol Workable {
func work()
}

protocol Breakable {
func takeBreak()
}

protocol Attendable {
func attendMeeting()
}

class Employee: Workable, Breakable, Attendable {


// Implement the specific protocols
}
```

### 5. Dependency Inversion Principle (DIP):

5. **Dependency Inversion Principle (DIP):** High-level modules should not depend on low-level modules;
both should depend on abstractions. Abstractions should not depend on details; details should depend on
abstractions.

Example: Inversion of Control with Dependency Injection

```swift
// Not following DIP
class Service {
// Service has a dependency on the concrete implementation
private let database: Database = Database()

func fetchData() {
// Use the database to fetch data

You might also like