CPSC 3720 - DAY 20 MARCH 10, 2017 ================================================================================ OBJECT DESIGN ------------- Optimizing Access ----------------- Repeated association traversals Look in sequence diagrams Is there an often repeated traversal that goes through many objects A->B->C->D and back? Can an association be added to go directly from A to D? In System Design, we eliminated redundant associations to make subsystem decomposition clear It may be more efficient to add some back in This can be a trade off if that association is between different subsystems. "Many" Associations Associations with "Many" can be inefficient Increases search time Can you reduce to a one to one association? Can be done with a qualified association Order the objects on the "many" side for faster searches Collapsing Objects ------------------ +-----------------------+ +------------------------+ | Person |--------------------------| SocialSecurity | +-----------------------+ | +------------------------+ | | | V +-----------------------------------+ | Person | +-----------------------------------+ | SSN:String | +-----------------------------------+ Delay Expensive Computations ---------------------------- Some objects may contain large data that is expensive to compute or load into memory. Is that data always neede? If not, don't always load/compute that data Use a proxy until that data is needed +-----------------------------------+ OBJECT DESIGN MODEL | Image | BEFORE TRANSFORMATION +-----------------------------------+ | filename: String data: byte[] | +-----------------------------------+ | paint() | +-----------------------------------+ | | V OBJECT DESIGN MODEL +-----------------------------------+ AFTER TRANSFORMAITON | Image | +-----------------------------------+ | filename: String data | +-----------------------------------+ | paint() | +-----------------------------------+ ^ | | +---------------------------------------------------+ | | +--------------------------------+ image +--------------------+ | ImageProxy |-----------------------| RealImage | +--------------------------------+ 1 0...1 +--------------------+ | filename:String | | data:byte[] | +--------------------------------+ +--------------------+ | paint() | | paint | +--------------------------------+ +--------------------+ Caching ------- You may have an expensive computation that's not likely to change Don't recompute every time Store the computed value Include a boolean to track when those values are still valid ***Time vs. Space Tradeoff*** Access Control Policy --------------------- Often considered part of System Design Different actors have different access functionality and data Modeled by association use cases with actors Which objects are shared among actors? Use an Access Matrix to track access control