Declaring a class that works with two constrained generic types
Now, it is time to code another protocol that will be used as a constraint later, when we define another class that takes advantage of generics with two constrained generic types. The following lines show the code for the DeeJayProtocol
protocol. The public
modifier followed by the protocol
keyword and the protocol name, DeeJayProtocol
, composes the protocol declaration, as follows. The code file for the sample is included in the swift_3_oop_chapter_06_10
folder:
public protocol DeeJayProtocol {
var name: String { get }
init(name: String)
func playMusicToDance()
func playMusicToSing()
}
The protocol declares a name: String
 read-only stored property and two method requirements: playMusicToDance
and playMusicToSing
. As you
learned in the previous chapter, the protocol includes only the method declaration because the classes that conform to...