This is not what is happening. HasSynchronization does not inherit from Entity. It simply requires that any type which conforms to HasSynchronization must inherit from Entity.
Therefore, the examples that you provided are not equivalent.
Furthermore, your alternative can quickly become very cumbersome once you have an entity that you'd like to have many components, for example:
protocol HasCustomComponentA {}
typealias HasCustomComponentAClassConstrained = Entity & HasCustomComponentA
protocol HasCustomComponentB {}
typealias HasCustomComponentBClassConstrained = Entity & HasCustomComponentB
class CustomEntity: HasCustomComponentAClassConstrained, HasCustomComponentBClassConstrained {}
This will not compile because now CustomEntity has a duplicate inheritance from Entity. Of course you could define another typealias like this:
typealias HasCustomComponentAHasCustomComponentBClassConstrained = Entity & HasCustomComponentA & HasCustomComponentB
But again, this is already cumbersome with just two components...
In addition to being cumbersome when dealing with many components, the alternative example you provided is not functionally equivalent to the first example, because in the alternative any class or struct can still conform to HasSynchronization.
So, we have established the difference here, so now we have to ask, what is the point of constraining HasCustomComponent to Entity at all? Well, the answer is, it allows you to add components to an Entity which can add to the functionality of the Entity, for example:
class BaseEntity {
var someProperty = true
}
protocol HasCustomComponent: BaseEntity {}
extension HasCustomComponent {
func doSomethingWithSomeProperty() {
if self.someProperty == true {
print("do something")
}
}
}
class CustomEntity: BaseEntity, HasCustomComponent {
override init() {
super.init()
doSomethingWithSomeProperty()
}
}
The only reason that this works is because HasCustomComponent knows for certain that self must conform to BaseEntity because of the type constraint on the protocol.