im not yet well exposed on creating a big architecture for the Inheritance concept when im dealing with big programs, and i came across with this issue, Serializing an Abstract class, consider my codes first
The Base Class(super)
public abstract class ElectronicAppliances implements Serializable { private String voltageType; public void setVoltageType(String voltageType) { this.voltageType = voltageType; } public String voltageType() { return voltageType; } }
and one of its Sub-class
public class Television extends ElectronicAppliances implements Serializable { private static final long serialVersionUID = 1L; private int width; private int heigth; private String displayType; public void setDisplayDimension(int width, int height) { this.width = width; this.heigth = height; } // LCD or CRT public void setTelevisionType(String type) { displayType = type; } public String getType() { return displayType; } }
my concern was, when the Super class(ElectronicAppliances) wasnt serializable, and i serialize a Television instance, i wasnt able to include the data members of the SuperClass(voltagetype), i came with the idea that i will serialize the parent class as well,
now my concern is, is this a good practice? ive been searching on google, i even ended up Reading design patterns, but its way too vast to explore for now, i need to clear my mind on this.
- my goal for serializing the abstract super-class was JUST to make its DATA MEMBERS serializable for its sub-classes implementations. i dont intend to write obejcts of the abstract class because as the concept says, abstracts cannot instantiate themselves, i just did it to make the instances of Television class serialize the ElectronicApplicances' data members, am i on the right track?