-
Notifications
You must be signed in to change notification settings - Fork 14
Single Inheritance and Multiple Inheritance Explained
Note: These images are from a slide deck that Matt Zumwalt made for the initial PCDM Sprint in 2015. If you need to edit or re-use them, feel free to do so.
Single inheritance is the classic object-oriented way to share functionality across mutliple classes.
Multiple Inheritance (aka "Mixins") is a common approach in Ruby. This pattern occurs in other programming languages, but it is especially prevalent with Ruby.
All of the hydra components emphasize multiple inheritance internally but tend to provide "Base" classes for consumers to inherit from in case they prefer Single Inheritance. These diagrams show how the hydra-pcdm and hydra-works gems support both approaches.
What are the different ways you can get the desired behaviors to cascade from top to bottom so that they all will be present in the classes at the bottom (ie. Sufia::GenericWork, Dissertation, etc)?
This approach uses single inheritance, but the actual behaviors are all in modules that could be mixed together using multiple inheritance.
This approach uses only mixins/modules, with no Superclass relationship. Though PCDM:Object, Works:BaseWork and Sufia:GenericWork are available for others to use as superclasses, this implementation doesn’t use them.
This shows how something downstream of hydra-pcdm and hydra-works can choose to use single inheritance without this blocking others from using multiple inheritance (mixins).
- Dive into Hydra-Works
- Lesson: Generate a Rails Application
- Lesson: Add the Hydra Dependencies
- Lesson: Start FCRepo and Solr
- Lesson: Start the Application & Search for Results
- Lesson: Define models with Hydra-Works
- Lesson: Create instances of Hydra-Works models
- Lesson: Explore Objects in Fedora and Solr
- Lesson: Make Blacklight Return Search Results
- BONUS Lessons
- Aggregations API Documentation
- Application Profile