1 / 21

What is Framework

Presentation on Designing a Persistence Framework With Patterns Submitted by WWW.ASSIGNMENTPOINT.COM. What is Framework. An extendable set of objects for related function. Example: GUI Framework, such as Java’s AWT or Swing

sak
Download Presentation

What is Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Presentation on Designing a Persistence Framework With PatternsSubmitted byWWW.ASSIGNMENTPOINT.COM www.assignmentpoint.com

  2. What is Framework • An extendable set of objects for related function. • Example: GUI Framework, such as Java’s AWT or Swing • Criteria of a framework: It provides an implementation for the core and unvarying functions, and includes a mechanism to allow plug in or to extend the functions. • Example: Developer can extend swing classes • Frameworks provide high degree of reuse. www.assignmentpoint.com

  3. Persistent Objects • Objects that are stored in persistent storage and brought into local memory during application use, e.g. ProductSpecification • Storage mechanisms • Object Databases • Relational Databases • Other formats e.g. XML etc. www.assignmentpoint.com

  4. Persistence Framework • Persistence Framework: A general purpose, reusable and extendable set of types that provide functionality to support persistent objects. • Persistence Service (or Subsystem): Actually provides the service, and will be created with a persistence framework. • O-R Mapping Service: A persistence service that is written to work with RDBs. www.assignmentpoint.com

  5. Requirements for the Persistence Service and Framework • The framework should provide the following functions • Store and retrieve objects in a persistent storage mechanism • Commit and rollback transactions. • Design should be extendable to support different storage mechanisms and formats, such as RDBs, records in flat files or XML in files. www.assignmentpoint.com

  6. Key Ideas for Persistence Framework • Mapping • Object identity • Database mapper • Materialization and dematerialization • Caches • Transaction state of object • Transaction operations • Lazy materialization • Virtual proxies www.assignmentpoint.com

  7. Pattern: Representing Objects as Tables • How to map an object to a record or relational database schema? Mapping objects and tables www.assignmentpoint.com

  8. Pattern: Object Identifier • Object Identifier pattern proposes assigning an object identifier (OID) to each record and object (or proxy of an object) • An OID is usually an alphanumeric value www.assignmentpoint.com Objects identifiers link objects and records

  9. Accessing a Persistence Service with a Facade The PersistenceFacade Class Class www.assignmentpoint.com

  10. Pattern: Database Mapper / Broker • PersistenceFacade – as true of all facades – does not do the work itself, but delegates requests to subsystem objects • Who should be responsible for materialization and dematerialization of objects from a persistent store? • Information Expert (or Expert) suggests the class itself • But violates low coupling and high cohesion www.assignmentpoint.com

  11. Direct Mapping vs. Indirect Mapping • Direct Mapping: If the class saves data itself • Workable if the database related code is automatically generated and injected into the class by a post-processing compiler • Indirect Mapping: Uses other objects to do the maping for persistent objects. Class Sale { total = … float getTotal () { } ……. void saveObject () { SQL code goes here } } Class Sale { total = … float getTotal () { } ……. } www.assignmentpoint.com

  12. www.assignmentpoint.com

  13. PersistenceFacade Class PersistenceFacade{ // …. public Object get (OID oid, Class persistenceClass) { // an Imapper is keyed by the Class of the persistence Object Imappermapper = (IMapper) mappers.get (persistenceClass) // delegate return mapper.get ( oid ) ; } } HashMap <IMapper> mappers = new HashMap <IMapper> () ; mappers.put ( new ProducSpecification (), new ProductSpecificationRDBMapper () ) ; Mappers.put ( new Sale (), new SaleRDBMapper () ) ; www.assignmentpoint.com

  14. Class PersistenceFacade{ // …. public Object get (OID oid, Class persistenceClass) { // an Imapper is keyed by the Class of the persistence Object Imappermapper = (IMapper) mappers.get (persistenceClass) // delegate return mapper.get ( oid ) ; } } Class ProductSpecificationRDBMapper { // …. Object get (OID oid) { ProductSpecificationps = new ProductSpecification () ; SQL statements to get produc specification from tbl_product_specification ps.setProductName (pName) ; ps.setPrice (pPrice) ; return ps ; } // …. } Hand Crafted mapper www.assignmentpoint.com

  15. Metadata-Based Mapper • Dynamically generate the mapping from an object schema to another schema (such as relational) • Mapping can be made also in external property files www.assignmentpoint.com

  16. Framework Design with the Template Method Pattern • Template Method pattern is at the heart of framework design • Familiar to most OO programmers, though not by name • The idea is to define a method (the template method) in a superclass that defines the skeleton of an algorithm • Template method invokes other methods some of which may be overridden in a subclass www.assignmentpoint.com

  17. Materialization with the Template Method pattern • If we were to program two / three mapper classes there will be some commonality in the code If ( object in cache ) return it Else create the object from its representation in storage save object in cache return it • The point of variation is how the object is created from storage www.assignmentpoint.com

  18. Template Method for mapper objects www.assignmentpoint.com

  19. Only table name DB Record Object from DB Record Overriding the hook method www.assignmentpoint.com Apply Template Again

  20. DB Record Object from DB Record www.assignmentpoint.com

  21. www.assignmentpoint.com

More Related