Python - Abstract Base Classes (ABCs)

Card Puncher Data Processing

About

Data Type - Abstract (ADT)

Management

Creation

Use the ABCMeta metaclass to create an ABC.

from abc import ABCMeta, abstractmethod

class MyAbstractClass(object):
        
        # specifying that is an abstract class
	__metaclass__ = ABCMeta

        # An attribute
        name = None

        def __init__(self, name):
             self.name = name

	@abstractmethod
	def my_abstract_method(self):
		"""
		blablabla
		:return: None
		"""
		return

Implementation

class MyClassImplementation(MyAbstractClass):

    def __init__(self):
        super().__init__("name")

    def my_abstract_method(self):
        """
        echo name
        :return: None
        """
        print (self.name)
        return





Discover More
Card Puncher Data Processing
Metaclass

A metaclass is a class that create a class The main purpose of a metaclass is to change the class automatically, when it's created. The main use case for a metaclass is creating an API. See 3115PEP...



Share this page:
Follow us:
Task Runner