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
From the course: Swift 5: Protocol-Oriented Programming
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What is protocol-oriented programming?2m 15s
-
(Locked)
Introducing the protocol5m 18s
-
(Locked)
Adopting protocols1m 54s
-
(Locked)
Conforming to protocols via extensions3m 38s
-
(Locked)
Understanding polymorphism4m
-
(Locked)
Protocol inheritance3m 41s
-
(Locked)
Adopting multiple protocols5m 50s
-
(Locked)
Protocol extensions3m 23s
-
(Locked)
Challenge: Removing tight coupling3m 13s
-
(Locked)
Solution: Removing tight coupling8m 33s
-
-
-
-
-