Click to edit Master title style Ibiza, June 4 th – 7 th 2011.

Slides:



Advertisements
Similar presentations
Ibiza June 4 th – 7 th Magento Developers Paradise Magento 2 Project Plans, Ideas and State Dmitriy Soroka System Architect.
Advertisements

3 Copyright © 2005, Oracle. All rights reserved. Designing J2EE Applications.
Chapter 10: Designing Databases
Apache Struts Technology
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
1 Copyright 1998 by Dragos Manolescu and Joseph W. Yoder Building Frameworks With Patterns “An Active Object-Model For A Dynamic Web-Based Application”
Spring, Hibernate and Web Services 13 th September 2014.
QAD Integrated Customization Toolkit (ICT)
©2007 · Georges Merx and Ronald J. NormanSlide 1 Chapter 5 Architecture-Driven Component Development.
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Object-Oriented Databases
Software Architecture Patterns (2). what is architecture? (recap) o an overall blueprint/model describing the structures and properties of a "system"
BUSINESS DRIVEN TECHNOLOGY
Reuse Activities Selecting Design Patterns and Components
Chapter One Overview of Database Objectives: -Introduction -DBMS architecture -Definitions -Data models -DB lifecycle.
Enterprise Object Framework. What is EOF? Enterprise Objects Framework is a set of tools and resources that help you create applications that work with.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Entity Framework Code First End to End
Introduction to the Spring Framework By: Nigusse A. Duguma Kansas State university Department of Computer Science Nov 20, 2007.
6-1 DATABASE FUNDAMENTALS Information is everywhere in an organization Information is stored in databases –Database – maintains information about various.
Introduction to Object-oriented programming and software development Lecture 1.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
Eric Westfall – Indiana University Jeremy Hanson – Iowa State University Building Applications with the KNS.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Database Technical Session By: Prof. Adarsh Patel.
Presenting Statistical Data Using XML Office for National Statistics, United Kingdom Rob Hawkins, Application Development.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 09. Review Introduction to architectural styles Distributed architectures – Client Server Architecture – Multi-tier.
.NET Database Technologies: Data Models and Patterns.
1 Another group of Patterns Architectural Patterns.
Oracle9i Performance Tuning Chapter 1 Performance Tuning Overview.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Building Applications with the KNS. The History of the KNS KFS spent a large amount of development time up front, using the best talent from each of the.
Storing Organizational Information - Databases
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
1 Mapping to Relational Databases Presented by Ramona Su.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans.
Structural Design Patterns
ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha Kraljevic Principal TSE.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 18 Slide 1 Software Reuse.
Design Patterns Definition:
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Java EE Patterns Dan Bugariu.  What is Java EE ?  What is a Pattern ?
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Date : 3/04/2010 Web Technology Solutions Class: PHP Web Application Frameworks.
Elaboration Iteration 3 – Part 3 - Persistence Framework -
Advanced Object-oriented Design Patterns Creational Design Patterns.
SEA Side – Extreme Programming 1 SEA Side Software Engineering Annotations Architectural Patterns Professor Sara Stoecklin Director of Software Engineering-
V 1.0 DBMAN 9 Inheritance Modeling + Relational Databases 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Module 9. Dealing with Generalization Course: Refactoring.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Enterprise Library 3.0 Memi Lavi Solution Architect Microsoft Consulting Services Guy Burstein Senior Consultant Advantech – Microsoft Division.
Introduction The concept of a web framework originates from the basic idea that every web application obtains its foundations from a similar set of guidelines.
Web Technology Solutions
Enterprise Service Bus
Design Patterns: MORE Examples
N-Tier Architecture.
Recent trends in estimation methodologies
MVC Architecture, Symfony Framework for PHP Web Apps
Entity Framework By: Casey Griffin.
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
.NET Database Technologies:
An Introduction to Software Architecture
Developing and testing enterprise Java applications
Presentation transcript:

Click to edit Master title style Ibiza, June 4 th – 7 th 2011

Application Models Design Lessons Learned in Magento Models by Anton Makarenko, PHP-Developer at Magento 2

Research Goals: Better maintainable model layer, less code coupling Better solution for multiple RDBMSs support

Application Models Design 1.Domain and Service Layers 2.Models Design in Magento 3.Collections Design in Magento 4.Entities and Service Layer in Doctrine ORM 5.Possible Solution for Magento

Application Models Design 1.DOMAIN AND SERVICE LAYERS Theoretical Background

Decomposing Model Layer by Role Domain model – an entity or business rule implementation Service model – application logic: instantiation, composition, collections and data delivery

Entity (Domain Model) Represents a real-world entity Defines data fields and a way to identify an entity Protects data integrity Implements domain behavior

Service Model Layer Implements arbitrary application logic Arbitrary hierarchy of models for: –Data mapping –Composition of models, domains –Utility purposes

Criteria for Creating Hierarchy of Models Complexity of task Necessity for different use cases Requirements for application flexibility

Model Hierarchy Detalization Toy Car Vehicle Car Truck Wheel Drivers Seat Frame

Data Sharing Between Models Entities CustomerQuoteProduct Application Entity Manager Configuration Framework Database access Caching

Horizontal Exchange One namespace between neighbors Allow dependencies on the same level Vertical Exchange Different namespaces = mapping between models of different hierarchy levels Strive to loose dependencies Data Sharing Between Models

Entity Model Enforce all required and valid data in constructor and setters Allow to inject data only through strict interface Service Model Stateless or with predictable state Laconic public interface Data Encapsulation in Models

Application Models Design 2.MODELS DESIGN IN MAGENTO Backwards Compatibility

What are Models in Magento? Models Business logic Entities Resource Models Entity persistence Data manipulation, indexing Collections Reading sets of data Reports

What are Models in Magento? Mage::getModel() Standalone domain models Entity domain models (Mage_Core_Model_Abstract) Mage::getResourceModel() Resource models (Mage_Core_Model_Resource_Abstract) – service layer Collections (Varien_Data_Collection_Db) – also service layer Mage::helper() Helpers (Mage_Core_Helper_Abstract) – a bit of service layer as well

Super Models

Reuse Through Inheritance Constrains designing classes hierarchy No natural is-a relation Fails attempt to reuse code by bloating interface Reuse Through Composition Real is-a relations, polymorphism Less coupling, more freedom in designing classes More scalable and more expensive in terms of number of objects in memory Super Models in Magento Backwards Compatibility

Mage_Core_Model_Abstract Service Interface save() load() delete() getResource() getCollection() afterLoad() afterCommitCallback() isObjectNew() Entity (Domain) Interface N/A

Varien_Object Cons Data Object __call() getData() setData() unsetData() hasData() Irrelevant Features Entity: Get/Set ID ID field name Service: Get/Set origData hasDataChanges()

Mage_Core_Model_Resource_Db_Abstract MethodsPurpose save(), load(), delete()Entity CRUD getIdFieldName(), hasDataChanged()Relation with abstract model afterLoad()Hook for collections getTable(), getMainTable(), getReadConnection() Provide direct DB access to resource collections _prepareDataForTable(), _checkUnique()Dynamic analysis of table structure on entity save operation

Entity and Resource Models Summary Dynamic entity structure: –Domain structural inconsistency –DB DDL overhead Scattered service logic –Contaminated entity models –Code encapsulation challenge –Exposure of DB layer Backwards Compatibility

Application Models Design 3.COLLECTIONS DESIGN IN MAGENTO

Collection Natural Purpose To enforce data of certain type Iterating capability The Lazy-Load pattern triggered by iteration Collection in Magento Enforce type – Yes Iterate & Lazy-load – Yes Data set formalization: –fields, filters, limitation, sorting Part of service layer: –Deals with database –Instantiates objects The Real Purpose of Collections

Components that Depend on Collections Domain models Service layer Controllers and view (templates) Special case – (admin) grids

Collections Hierarchy Varien_Data_Collection Varien_Data_Collection_Db Mage_Core_Model_Resource _Db_Collection_Abstract Mage_Cms_Model_Resource _Page_Collection Mage_Core_Model_Resource _Abstract Mage_Core_Model_Resource _Db_Abstract Mage_Cms_Model_Resource _Page Mage_Core_Model_Resource Varien_Db_Adapter_*

Collections as Resources Duplication of resource layer logic Necessity to break encapsulation Necessity to implement collection class for each entity Backwards Compatibility

The Triangle Collections Resource Layer Domain Entities 3x ~200

Application Models Design 4.ENTITIES AND SERVICE LAYER IN DOCTRINE ORM

What is ORM Magento Doctrine ORM 2.x

Doctrine ORM How Doctrine ORM Works XML, YAML, PHPDoc Entity Manager DB Other Domain and Service Models Entities OrderCustomerProduct Controller, View…

Can Doctrine ORM Be Adopted in Magento? A ready solution for domain and service layers Entities – a best practice implementation Entity manager and data persistence Collections Database abstraction layer (DBAL)

Doctrine ORM Cant Be Adopted in Magento Migration efforts to DBAL Potential performance issues: –There are up to 30 classes loaded to instantiate an entity –Objects initialization through unserialize() – possible performance bottleneck

Future Compatibility with Doctrine ORM Entity fields to be declared as class attributes One or more entity fields to serve as identity key

Application Models Design 5.POSSIBLE SOLUTION FOR MAGENTO Magento 2

Implementing Entities Move out service layer logic from domain models: –No persistence handling –No cascade handling of other entities Enforce domain model consistency using strict constructor, type hinting in setters and declared fields

OrigData Use Cases getOrigData($key) –track changes before save (service layer) getOrigData() –log object changes (Enterprise_Logging) hasDataChanges() –rare specific cases in different places (service, controllers)

Memento Pattern for Entities Data

Implementing Service Layer Entity managers: generic for primitive entities, custom for complex entities Data (database) access inside entity manager = disband resource models Implement data set handling in entity managers (ex-collections territory)

New Entity Manager Responsibilities Deal with DB access layer directly CRUD operations Get collection data from DB

Service Layer and Multiple RDBMSs Zend_Db_Adapter_Abstract Zend_Db_Adapter_Pdo_Mysql Varien_Db_Adapter_Pdo_Mysql

Service Layer and Multiple RDBMSs Zend_Db_Adapter_Abstract Zend_Db_Adapter_Pdo_Mysql Varien_Db_Adapter_Pdo_Mysql Zend_*_Oracle Zend_*_Pdo_Mssql Varien_*_Oracle Varien_*_Pdo_Mssql

Service Layer and Multiple RDBMSs

Service Layer and Application Resources Slightly reduced collections responsibility: No more DB layer access No more objects instantiation Data set formalization delegated to separate utility class ~2001

Making it Work Together

Summary, Q & A Better maneuver space for domain models DB abstraction layer improved for better multiple RDBMSs support Lightweight service layer Thank you!