0

Is there anything wrong with inheritance in which child class is only used to present parent's values in a different way?

Example:

class Parent(db.Model):

    __tablename__ = u'parent'

    parent_entry_id = db.Column(db.Integer, primary_key=True)
    parent_entry_value = db.Column(db.BigInteger)

class Child(Parent):

   __tablename__ = u'child'

   @property
   def extra_value(self):
       return unicode(self.parent_entry_id) + unicode(self.parent_entry_value)

No new values will be added Child class, thus Joined Table, Single Table or Concrete Table Inheritance, as for me, is not needed.

1 Answer 1

1

If you're simply changing how you display the data from the class, I'm pretty sure you don't need a __tablename__.

Additionally, though I don't know your exact problem domain, I would simply just add the property on the original class. You could argue that you're adding some extra behavior to your original class, but that seems like a bit of a flimsy argument in this case.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, yes - I've forgotten to remove __tablename__ from Child. It shouldn't be there. Except typo is this "simple" inheritance ok in this case?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.