Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OOP1 - StoreGUI

OOP1 - StoreGUI

Manatsawin Hanmongkolchai

December 24, 2013
Tweet

More Decks by Manatsawin Hanmongkolchai

Other Decks in Programming

Transcript

  1. Static • Many things were stored in static fields •

    Bills, Customers are stored in static ArrayList • Get a bill: Bill.bills.get(0); • Try a login:
 Customer.checkLogin(“username”, “password”);
  2. HashMap • Like ArrayList, but with key-value pair. • HashMap<String,

    String> hm = new HashMap<String, String>();
 hm.add(“key”, “value”);
 hm.get(“key”); // return “value” • Used to implement a basic key-value database with ArrayList as value • All data in store are saved to a static HashMap in FileStorage class
  3. Serializable • We don’t use our own save format, we

    use Java’s serializable format. • Just implement interface “Serializable” in classes and let Java do it magic. • HashMap, array, primitive types, ArrayList are implementors of Serializable interface • Read more: http://pagist.info/6f66495127be09d45180
 (available in my Facebook)
  4. Facade • We have a lot of things to save

    and load: • Customer • Store stock data • Bills • Solution: Facade save
  5. Facade • Instead of firing save for every objects, there

    is an method that will do it. • To save: Persistent.save(); • Will call save for Customer, Bills, Stock and save to file.
  6. Cloud backup • Move data between computer or to backup

    data • Store with the same key will download the same data. • Using OpenKeyVal service (openkeyval.org)
  7. Cloud • OpenKeyVal is simple: • POST http://api.openkeyval.org/STOREGUI_default_data
 data =

    …. • GET http://api.openkeyval.org/STOREGUI_default_data
 Return the data given (try this URL in your browser) • storedata.txt is sent to OpenKeyVal using base64 encoding to make it plain text
  8. Singleton • Object that have only one instance in an

    application Singleton - instance : Singleton + getInstance() : Singleton class Singleton{ private static Singleton instance = new Singleton(); public Singleton getInstance(){ return instance; } }
  9. Singleton • Store and shopping cart is singleton • No

    need to pass store instance around, just Store.getInstance() everywhere • Fixed a whole lot of bugs dealing with data inconsistent in pages. • Shopping cart’s singleton is required to save development time due to existing code structure