Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python between inheritance and composition

"""
Choosing Between Inheritance and Composition in Python
Python, as an object oriented programming language, supports both inheritance 
and composition.
You saw that inheritance is best used to model an is a relationship, whereas
composition models a has a relationship.

Sometimes, it’s hard to see what the relationship between two classes should
be, but you can follow these guidelines:

	Use inheritance over composition in Python to model a clear is a 
    relationship. First, justify the relationship between the derived
    class and its base. Then, reverse the relationship and try to justify it. 
    If you can justify the relationship in both directions, then you should
    not use inheritance between them.

	Use inheritance over composition in Python to leverage both the interface
    and implementation of the base class.

	Use inheritance over composition in Python to provide mixin features to
    severalunrelated classes when there is only one implementation of that
    feature.

	Use composition over inheritance in Python to model a has a relationship
    that leverages the implementation of the component class.

	Use composition over inheritance in Python to create components that can
    be reused by multiple classes in your Python applications.

	Use composition over inheritance in Python to implement groups of 
    behaviors and policies that can be applied interchangeably to other 
    classes to customize their behavior.

	Use composition over inheritance in Python to enable run-time behavior
    changes without affecting existing classes.
"""
Comment

PREVIOUS NEXT
Code Example
Python :: pandas value in series 
Python :: python factor number 
Python :: check if item exists in list python 
Python :: python tuple and dictionary 
Python :: hide turtle 
Python :: merge 2 dataframes in python 
Python :: Python: Extracting XML to DataFrame (Pandas) 
Python :: torch print full tensor 
Python :: login url 
Python :: pyautogui doc 
Python :: keras loss plot 
Python :: python spawn process 
Python :: Normalize columns in pandas dataframe 
Python :: get index of dataframe 
Python :: keyboard write python 
Python :: check audio playing on windows python 
Python :: how to convert pandas price column to integer 
Python :: py function 
Python :: python tuple get index of element 
Python :: removing duplicates from django models data 
Python :: python jinja2 from string 
Python :: stack more system in python 
Python :: python fiboncci 
Python :: python sum of array until index 
Python :: random integer 
Python :: pandas aggregate dataframe 
Python :: exit a pygame program 
Python :: sphinx autodoc extension 
Python :: plt.tight_layout() cuts x axis 
Python :: how to save frames in form of video in opencv python 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =