Southperry.net
Is this code smell? - Printable Version

+- Southperry.net (https://www.southperry.net)
+-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14)
+--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58)
+--- Thread: Is this code smell? (/showthread.php?tid=35758)



Is this code smell? - Fiel - 2011-01-06

Is it considered bad practice to have a higher level code pass messages through one layer of abstraction? Like this:

Code:
class HigherAbstraction:
  def __init__(self):
    self.bar = LowerAbstraction()

  def Spam(self):
    return self.bar.Spam()

class LowerAbstraction:
  def Spam(self):
    return 1

this = HigherAbstraction()
this.Spam()

Is there a way that this can be better factored? Sometimes I have to create several different HigherAbstraction types of classes where all instances of HigherAbstraction also could use functionality from LowerAbstraction.


Is this code smell? - Mute - 2011-01-06

codes have scent?


Is this code smell? - AngelSL - 2011-01-07

Fiel Wrote:Is it considered bad practice to have a higher level code pass messages through one layer of abstraction? Like this:

Code:
class HigherAbstraction:
  def __init__(self):
    self.bar = LowerAbstraction()

  def Spam(self):
    return self.bar.Spam()

class LowerAbstraction:
  def Spam(self):
    return 1

this = HigherAbstraction()
this.Spam()

Is there a way that this can be better factored? Sometimes I have to create several different HigherAbstraction types of classes where all instances of HigherAbstraction also could use functionality from LowerAbstraction.

Code:
class HigherAbstraction(LowerAbstraction):
  def __init__(self):
    pass

class LowerAbstraction:
  def Spam(self):
    return 1

this = HigherAbstraction()
this.Spam()

Class inheritance. Also note that all methods in Python are virtual, so if you want to call a method from your base class in an overridden method, use something like BaseClassName.methodname(self, param1, param2).

[FONT] seems to be broken. :\