inheritance

Can I reuse a column across subclasses in a Hibernate table-per-hierarchy inheritance strategy?

纵饮孤独 提交于 2021-02-07 08:36:35
问题 In a simple inheritance tree, an abstract superclass has two subclasses. The subclasses both store a key-value pair, but but one will be holding a type Encrypted String, and the other one a plain old String. Now, my question is can I do this: @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract Attribute { @Id private Integer id; @Column(name="attribute_key") private String key; } @Entity public EncryptedAttribute extends Attribute { @Column(name="attribute_value")

Downcast: why: ‘A’ is an inaccessible base of ‘B’?

我只是一个虾纸丫 提交于 2021-02-07 07:21:46
问题 Unlike other examples of this error message i already have a pointer to A and want to retrieve the actual child class. This kind of arrangement is part of some C++ wrapped C code there A is some POD C structure (whatswhy no dynamic cast) and test is some callback in C that calls C++ functionality and to retrieve the correct object the cast should be used. But to prevent C++ user code messing the C-Baseclass i would like to have the inheritance protected . MSVC does not complain about this but

Downcast: why: ‘A’ is an inaccessible base of ‘B’?

牧云@^-^@ 提交于 2021-02-07 07:21:37
问题 Unlike other examples of this error message i already have a pointer to A and want to retrieve the actual child class. This kind of arrangement is part of some C++ wrapped C code there A is some POD C structure (whatswhy no dynamic cast) and test is some callback in C that calls C++ functionality and to retrieve the correct object the cast should be used. But to prevent C++ user code messing the C-Baseclass i would like to have the inheritance protected . MSVC does not complain about this but

Overriding class variables in python

可紊 提交于 2021-02-07 05:04:37
问题 I'm trying to understand a bit how Python (2.6) deals with class, instances and so on, and at a certain point, I tried this code: #/usr/bin/python2.6 class Base(object): default = "default value in base" def __init__(self): super(Base, self).__init__() @classmethod def showDefaultValue(cls, defl = default): print "defl == %s" % (defl) class Descend(Base): default = "default value in descend" def __init__(self): super(Descend, self).__init__() if __name__ == "__main__": Descend

Inheritance and casting in Java

帅比萌擦擦* 提交于 2021-02-07 03:28:34
问题 I have a question about inheritance and casting in Java. I have the following two example classes and a test class, and I state my question after the classes: public class Automobile { public int var; public Automobile () { var = 1; } public String toString () { return "AUTOMOBILE: " + var; } } public class Porsche extends Automobile { public int var; public Porsche () { var = 2; } public String toString () { return "PORSCHE: " + var; } } public class Test { public static void main (String []

Inheritance and casting in Java

半腔热情 提交于 2021-02-07 03:26:58
问题 I have a question about inheritance and casting in Java. I have the following two example classes and a test class, and I state my question after the classes: public class Automobile { public int var; public Automobile () { var = 1; } public String toString () { return "AUTOMOBILE: " + var; } } public class Porsche extends Automobile { public int var; public Porsche () { var = 2; } public String toString () { return "PORSCHE: " + var; } } public class Test { public static void main (String []

Inheritance and casting in Java

北慕城南 提交于 2021-02-07 03:26:40
问题 I have a question about inheritance and casting in Java. I have the following two example classes and a test class, and I state my question after the classes: public class Automobile { public int var; public Automobile () { var = 1; } public String toString () { return "AUTOMOBILE: " + var; } } public class Porsche extends Automobile { public int var; public Porsche () { var = 2; } public String toString () { return "PORSCHE: " + var; } } public class Test { public static void main (String []

Avoid casting in inherited java-classes

一世执手 提交于 2021-02-07 00:01:03
问题 I have a class: class MyClass { public MyClass getParent() { ... } public MyClass[] getChildren() { ... } .... } and a subclass MySubClass extends MyClass { public String getId() { } ... } Everytime I used getChildren() or getParent() on an instance of MySubClass , I have to cast the result of theese methods, e.g.: MySubClass sub = new MySubClass(); ((MySubClass)sub.getParent()).getId(); Is there any way (by language or design) to avoid that casting? Thanks for any ideas! Update What I would

Avoid casting in inherited java-classes

十年热恋 提交于 2021-02-07 00:00:57
问题 I have a class: class MyClass { public MyClass getParent() { ... } public MyClass[] getChildren() { ... } .... } and a subclass MySubClass extends MyClass { public String getId() { } ... } Everytime I used getChildren() or getParent() on an instance of MySubClass , I have to cast the result of theese methods, e.g.: MySubClass sub = new MySubClass(); ((MySubClass)sub.getParent()).getId(); Is there any way (by language or design) to avoid that casting? Thanks for any ideas! Update What I would

Avoid casting in inherited java-classes

随声附和 提交于 2021-02-07 00:00:36
问题 I have a class: class MyClass { public MyClass getParent() { ... } public MyClass[] getChildren() { ... } .... } and a subclass MySubClass extends MyClass { public String getId() { } ... } Everytime I used getChildren() or getParent() on an instance of MySubClass , I have to cast the result of theese methods, e.g.: MySubClass sub = new MySubClass(); ((MySubClass)sub.getParent()).getId(); Is there any way (by language or design) to avoid that casting? Thanks for any ideas! Update What I would