본문 바로가기

Programming/Swift

When to Use Inheritance

Inheritance is a useful programming concept, but it is easy to use inappropriately. Often interfaces do the job better. This topic and When to Use Interfaces help you understand when each approach should be used.

Inheritance is a good choice when:

  • Your inheritance hierarchy represents an "is-a" relationship and not a "has-a" relationship.

  • You can reuse code from the base classes.

  • You need to apply the same class and methods to different data types.

  • The class hierarchy is reasonably shallow, and other developers are not likely to add many more levels.

  • You want to make global changes to derived classes by changing a base class.

These considerations are discussed in order below.

 

docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/27db6csx(v=vs.90)?redirectedfrom=MSDN

 

When to Use Inheritance

When to Use Inheritance 11/16/2012 8 minutes to read In this article --> Inheritance is a useful programming concept, but it is easy to use inappropriately. Often interfaces do the job better. This topic and When to Use Interfaces help you understand when

docs.microsoft.com

Note that this article uses "is a" and "has a" instead of "kind of" and "contains", respectively.

'Programming > Swift' 카테고리의 다른 글

Error  (0) 2020.11.06
Protocols  (0) 2020.11.06
Class: UIPickerView  (0) 2020.10.30
Class: URLSession  (0) 2020.10.29
UICollectionViewFlowLayout  (0) 2020.10.29