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.
Designing with classes: Subclassing
From the course: Swift 5: Protocol-Oriented Programming
Designing with classes: Subclassing
- We've seen that embedding all the features in a class is not a viable solution. God Objects with too many responsibilities lead to coupling. Tight coupling is the root of severe problems in object oriented systems, so we should do our best to avoid it. We're going to refactor the tagged data class and breakout some of the functionality into subclasses. So I create a new playground page called "SubClasses." And lets rename the previous playground page to "GodObject." Next I select the taggeddataclasses declaration including the tag and data properties and the initializer code and copy it or to our newly created page. Command C and I switch here, command V. Let's close our classes declaration. Now we have a class with one ratified responsibility. It works some data that can be identified using a tag. Next we implement the local persistent feature. This time we rely on subclassing instead of adding this feature to the tag data…
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.