Page 154 - DCAP308_OBJECT_ORIENTED_ANALYSIS_AND_DESIGN
P. 154

Object Oriented Analysis and Design




                    Notes          Advantages

                                       Easy and efficient to construct and use
                                       More readily repairable

                                   Disadvantages

                                       No rollback
                                       No direct complex structure support

                                       Complex structure requires a grammar for file Format
                                   Flat File Storage and Retrieval


                                       Useful to define two components (or classes)
                                            Reader reads file and instantiates internal object Structure
                                            Writer traverses internal data structure and writes out Presentation
                                       Both can (should) use formal grammar

                                            Tools support: Yacc, Lex.
                                   Java Data Marshalling


                                       Provides a means of “serializing” a set of objects
                                       Requires classes to implement the “Serializable” Interface.
                                       Stream can be written/read to a file
                                       Stream can be written/read to a network socket

                                   Serialization Example:

                                                           Figure 12.4: Serialization Example


                                             private void
                                             writeObject(java.io.ObjectOutputStream out)
                                             throws IOException;
                                                        private void
                                               readObject(java.io.ObjectInputStream in)
                                             throws IOException, ClassNotFoundException;


                                             FileOutputStream ostream = new
                                             FileOutputStream("t.tmp");
                                             ObjectOutputStream p = new
                                             ObjectOutputStream(ostream);
                                             p.writeInt(12345);
                                             p.writeObject("Today");
                                             p.writeObject(new Date());
                                             p.flush(); ostream.close();






          148                               LOVELY PROFESSIONAL UNIVERSITY
   149   150   151   152   153   154   155   156   157   158   159