I know that UICollectionViewDelegateFlowLayout is a protocol while UICollectionViewFlowLayout is a class, and I know the difference between a protocol and a class. From my understanding, I can have a class to follow the UICollectionViewDelegateFlowLayout protocol to achieve the exact same effect as having a class inherited from UICollectionViewFlowLayout. I reach this conclusion by finding such relations between the protocol and the class: UICollectionViewDelegateFlowLayout ------------- UICollectionViewFlowLayout collectionView:layout:sizeForItemAtIndexPath:---- itemSize collectionView:layout:insetForSectionAtIndex:---- sectionInset – collectionView:layout:referenceSizeForHeaderInSection: -- headerReferenceSize – collectionView:layout:referenceSizeForFooterInSection: -- footerReferenceSize
I also read the following in the reference of the protocol: "All of the methods in this protocol are optional. If you do not implement a particular method, the flow layout delegate uses values in its own properties for the appropriate spacing information" So my understanding is: if a CollectionView has a layout property and a delegateFlowLayout, the delegateFlowLayout can potentially overwrites something. In other words, I can have both and the protocol will take higher priority. Right?
So, what is the logic behind inventing a protocol and a class that do the same thing?