Skip to main content
deleted 4 characters in body
Source Link
Ohad
  • 2.7k
  • 20
  • 15

First, Notenote that there is no function overloading in python, thus this:

class Shape:        
    def __init__(self, centrePoint, colour, width, height):
        ...

    def __init__(self, centrePoint, radius, colour):
        ...

will get your first function to be 'overridden' by the second.

As a general rule of thumb, the main idea behind the concept of a common Base/Abstract class is to decouple the implementation from the interface (note the python conventions, lower_case_with_underscores for function names, not camleCase):

class Shape: 
  __metaclass__ = ABCMeta

  @abstractmethod
  def get_area(self):
    pass

  move, scale, scale_vertically, scale_horizontally, print...

Now that I have my abstract yet operable (as in 'Every shape can be scaled, moved..') base class, which is completely unaware of how a circle is constructed, moved or scaled. I can then start to implement the sub-classes: Rectangle, Circle, and so on.

First, Note that there is no function overloading in python, thus this:

class Shape:        
    def __init__(self, centrePoint, colour, width, height):
        ...

    def __init__(self, centrePoint, radius, colour):
        ...

will get your first function to be 'overridden' by the second.

As general rule of thumb, the main idea behind the concept of a common Base/Abstract class is to decouple the implementation from the interface (note the python conventions, lower_case_with_underscores for function names, not camleCase):

class Shape: 
  __metaclass__ = ABCMeta

  @abstractmethod
  def get_area(self):
    pass

  move, scale, scale_vertically, scale_horizontally, print...

Now that I have my abstract yet operable (as in 'Every shape can be scaled, moved..') base class, which is completely unaware of how a circle is constructed, moved or scaled. I can then start to implement the sub-classes: Rectangle, Circle, and so on.

First, note that there is no function overloading in python, thus this:

class Shape:        
    def __init__(self, centrePoint, colour, width, height):
        ...

    def __init__(self, centrePoint, radius, colour):
        ...

will get your first function 'overridden' by the second.

As a general rule of thumb, the main idea behind the concept of a common Base/Abstract class is to decouple the implementation from the interface (note the python conventions, lower_case_with_underscores for function names, not camleCase):

class Shape: 
  __metaclass__ = ABCMeta

  @abstractmethod
  def get_area(self):
    pass

  move, scale, scale_vertically, scale_horizontally, print...

Now that I have my abstract yet operable (as in 'Every shape can be scaled, moved..') base class, which is completely unaware of how a circle is constructed, moved or scaled. I can then start to implement the sub-classes: Rectangle, Circle, and so on.

Source Link
Ohad
  • 2.7k
  • 20
  • 15

First, Note that there is no function overloading in python, thus this:

class Shape:        
    def __init__(self, centrePoint, colour, width, height):
        ...

    def __init__(self, centrePoint, radius, colour):
        ...

will get your first function to be 'overridden' by the second.

As general rule of thumb, the main idea behind the concept of a common Base/Abstract class is to decouple the implementation from the interface (note the python conventions, lower_case_with_underscores for function names, not camleCase):

class Shape: 
  __metaclass__ = ABCMeta

  @abstractmethod
  def get_area(self):
    pass

  move, scale, scale_vertically, scale_horizontally, print...

Now that I have my abstract yet operable (as in 'Every shape can be scaled, moved..') base class, which is completely unaware of how a circle is constructed, moved or scaled. I can then start to implement the sub-classes: Rectangle, Circle, and so on.