From the course: Swift 5: Protocol-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Removing tight coupling

Challenge: Removing tight coupling

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

Challenge: Removing tight coupling

(upbeat music) - [Instructor] And here's the chapter challenge. Let's have a look at the following playground. We have a payment controller class that declared two properties, Amazon service and Etsy service. It has an initializer and the method that calculates how much money we are making on Amazon and Etsy. The Amazon service and the assay service types are defined in the services does Swift file. Their implementation is straightforward. Whenever we sell something on the given platform, the profit gets added to a private variable. Amazon service exposes orders placed and Etsy service provides the method items sold for this purpose. Each class has a property that returns the total profit earnings and total sold. Now let's go back to the main playground file. Do use these classes. We first create an Amazon service and an Etsy service instance. Then we instantiate the payment controller by passing in the service…

Contents