Details:
My program is a grade book with 5 classes that are all aggregated. GradeBook has courses, Course has Categories, Category has Grades (all ArrayLists). My program also has a StateManager whose sole purpose is to return references to Objects because of the deep aggregation. In my Driver I do not create an instance of a GradeBook but a statemanager which has a static instance of a GradeBook with methods to return references.
My goal is to save all of this data to be reopened when the program is rerun.
Questions:
When I write the file all I need to do is write the StateManager object, correct? I think I’ve even accomplished this. I have the program create a “gradebook.data” file. Is there a way to open the .data file in a text program and see if it is writing correctly?
Where do I open the object again with inputstream? In the static main method or in the beginning of my method that initializes all of the graphics?
Thanks
Serializing
StateManagerwon’t do anything because you have astaticreference to theGradeBook. This is in itself a code smell, but here it has the physical repercussion of not getting serialized — only instance fields get serialized. So remove thestaticqualifier. You can make theStateManageritself a singleton and have astaticreference to it.However, I am still in doubt as to why you don’t serialize the
GradeBookinstance. That would be a far more logical approach. We don’t usually serialize service objects, but data objects, and you already have that separation.