Post on 18-Nov-2014
description
ScaffoldingEMF
Version 1.0
What is scaffolding ?
• Scaffolds are temporary structures that physically support workers while they complete jobs that would otherwise be impossible(HH93, p138)
Scaffolding in software
• Ruby on Rails• *Rails scripting frameworks bring
blazing fast productivity in their own specific technological space
• Mainly through Scaffolding !
Ruby on Rails Scaffolding
• Meta-Programming• Scaffolding works at the code level• Scaffolding engine operates on code as a model• Can be either– Static : on demand– Dynamic : transparently on your behalf
Entity.rb
DAO.rb
Others
• Ruby On Rails• Grails• Spring ROO• Play!• CakePHP• Monorail• Symfony• …
What’s the point ?
• Model-Driven brings quality, durability, maintainability
• What about productivity ?– Goal: Enhance modeling
expressiveness, simplicity and overwhole productivity
What is Scaffolding applied to Modeling ?
• Creating partial model structures on behalf of the designer that he would otherwise have to create by himself
Model Scaffolding taxonomy
• Blind versus In-Place Scaffolding• Static versus Dynamic Scaffolding• The greener the better
Model Scaffolding taxonomy
1. Classical code generation2. Compensated code generation3. « Blind » scaffolding4. « In-Place » scaffolding
• Each static or dynamic
Sample problem domain
• 3-Tiers Architecture• DSL containing concepts– Entity– DAO– Service
• Java code is generated
• Légende
GenerationReference
Model separation
File
Entity or DAO
Service
ScaffoldedGenerated
Hand-written
Color code
Classical code generation 1/2
• Entities are modeled• Entity and DAO source
codes are generated from the modeled Entity
• Problem: What if you want to define queries in your model ?
Entity
Entity.javaDAO.java
Model
Text
Classical code generation 2/2
• Entity and DAOs are modeled• Entity source code is
generated from the modeled Entity
• DAO source code is generated from modeled DAO
• DAOs which are not modeled are not generated
• Problem: You need to define all DAOs…
• Even those that only do CRUD
Entity
Entity.javaDAO.java
Model
Text
DAO
Compensated code generation
• Source code is still generated for modeled elements
• For Entities which have no modeled DAO, we compensate by generating source code for the DAO from the modeled Entity
• Advantage: Only custom DAOs are modeled
• Problem: DAO code generation logic is duplicated– Entity -> DAO.java– DAO -> DAO.java
EntityOne DAO
OneEntityTwo
One.java
OneDAO.java
Two.java
TwoDAO.java
Model
Text
Generation « Blind » Model Scaffolding
• Each model is a step in the MDSD chain
• An intermediate step is introduced• Each model can only « see » the
model before
• Existing elements are copied as is• A DAO is generated for each entity
which has no DAO
• Advantage: Only one DAO code generation logic
• Problem: How do you reference scaffolded elements
EntityOne
EntityOne
EntityTwo DAO
TwoDao
EntityTwo
DAOTwoDao
DAOOneDao
One.java
OneDAO.javaTwo.java
TwoDAO.java
Model i
Model i-bis
Model i+1
How to reference scaffolded elements ?
• The problem is illustrated by introducing a service
• The ‘Alpha’ service can reference the modeled DAO ‘TwoDao’ but not the scaffolded DAO ‘OneDao’
• The scaffolded DAO ‘OneDao’ is located in a model that the ‘Alpha’ service cannot see
• Problem: « Blind » scaffolding doesn’t allow scaffolded elements referencing
EntityOne
EntityOne
DAOOneDao
ServiceAlpha
Modèle i
Modèle i-bis
EntityTwo
DAOTwoDao
« In-place » Model Scaffolding
• ‘OneDao’ DAO is scaffolded in the same model as Entity ‘One’
• The DAO is « visible » without being materialized in the input model
• Advantage: Le ‘Alpha’ service can reference the scaffolded DAO ‘OneDao’
• Problem: How to customize a scaffolded element ?
EntityOne
DAOOneDao
One.java
AlphaService.java
OneDao.java
ServiceAlpha
Model i
Model i+1
Takeover 1/3: Overview
• User can take over scaffolded elements
• The over taken element is then materialized in the input model
• Advantage: The DAO can be customized
EntityOne
DAOOneDao
ServiceAlpha
Iteration n
Iteration n+1
EntityOne
DAOOneDao
ServiceAlpha
Takeover 2/3: Zoom
• After the DAO taking over, CRUD methods are still scaffolded
• Advantage: No need to manually input previously scaffolded elements
EntityOne
ServiceAlpha
Iteration n
EntityOne
ServiceAlpha
DAOOneDao
createread
updatedelete
DAOOneDao
createread
updatedelete
Iteration n+1
Takeover 3/3: Customisation
• Let’s add a finder finder• CRUD methods are still
scaffolded
• Advantage: Only customizations are hand written, CRUD methods are scaffoldedEntity
OneServiceAlpha
DAOOneDaocreateread
updatedelete
myFinder
EntityOne
ServiceAlpha
DAOOneDao
createread
updatedelete
Iteration n+1
Iteration n+2
Deletion 1/2: The problem
• What happens if the user deletes an element for which elements were scaffolded ?
• Scaffolded elements must also be deleted
EntityOne
DAOOneDao
One.java
AlphaService.java
OneDao.java
ServiceAlpha
Model i
Model i+1
Deletion 2/2: solutions
• Need to keep track of scaffolded elements
• Only really a problem with dynamic « in-place » scaffolding
• For static and/or « blind » scaffolding, scaffolded elements can just be computed all over again
Model scaffolding comparison
What Scaffolding engine ?
• A model to model transformation engine ?– ATL– Xtend– QVT Operational– QVT Relational– Obeo Transfo– …
• A rule engine ?– Drools– Any OO Rule Engine …
A rule engine ??
• Scaffolding rules as production rules• The model as a working memory• Model elements as facts• When a given condition is met, new facts are
inserted into working memory• Those new facts are attached to the model as new
elements
Rule engine sync process
EntityOne
DAOOneDao
Working Memory
Model
EntityOne
DAOOneDao
reference
reference
synchroniz
e
synchroniz
e Scaffolding Rule
Drools sample rule
• Sample Drools DAO scaffolding rule
MDSD Scaffolding benefits
• Accelerates modeling• Allows to quickly come up with a working model• The user starts from the begining with a complete model
(complete in the direction the scaffolding takes him)• Provides the user with a fast feedback• Allows to enrich the input model as well as facilitating its usage
for the new user• Brings flexibility while keeping simplicity• Scaffolding can be complemented by code generation and model
validation• The user can whenever he wants take over the scaffolded
elements in order to customize them