Descargar la presentación
La descarga está en progreso. Por favor, espere
Publicada porIñigo Trevino Modificado hace 9 años
1
Arquitectura de software dirigida por modelos (Model-Driven Architecture) Liliana Favre UNCPBA2006
2
Model-Driven Development MDD
3
Model-driven Development (MDD) Un desarrollo MDD distingue al menos las siguientes etapas: La construcción de un modelo del dominio, denominado CIM, que expresa la lógica del negocio desde una perspectiva independiente de la computación. La construcción de un modelo del dominio, denominado CIM, que expresa la lógica del negocio desde una perspectiva independiente de la computación. La construcción de un modelo, denominado PIM, que expresa la funcionalidad del sistema en forma independiente de las características de plataformas de implementación específicas. La construcción de un modelo, denominado PIM, que expresa la funcionalidad del sistema en forma independiente de las características de plataformas de implementación específicas. La transformación de un PIM en uno o más modelos en una plataforma específica, denominados PSM. La transformación de un PIM en uno o más modelos en una plataforma específica, denominados PSM. La transformación de modelos PSM a modelos de implementación, denominados ISM. La transformación de modelos PSM a modelos de implementación, denominados ISM.
4
MDD (Model-Driven Development) PIM PSM J2EE PSM REL PSM dotNET CODE CIM
5
MDD- Modelos y metamodelos MDD- Modelos y metamodelos PIM METAMODEL PIM MODEL PSM -.NET METAMODEL PSM-REL METAMODEL PSM-J2EE METAMODEL CODE METAMODEL CODE METAMODEL CODE METAMODEL PSM- J2EE PSM- REL PSM-.NET CODE
6
Transformaciones y metamodelos “es-instancia-de” RefinamientoPIM-PSM Refinamiento PIM-PIMmetamodelo PSM- PSMmetamodelo PSM- PSMmetamodelo “es-instancia-de” PIM PSM MetamodeloPIM MetamodeloPSM
7
Formalización de metamodelos MOF
8
Meta Object Facility MOF MOF captura la diversidad de estándares de modelamiento para integrar diferentes tipos de modelos y metadatos e intercambiarlos entre diferentes herramientas. UML 2.0 está alineado con MOF, es una instancia de MOF. El núcleo de UML y de MOF comparten los elementos de metamodelado. En UML 2.0 los conceptos de MOF y de UML Superstructure derivan de conceptos de UML Infrastructure
9
MOF Las construcciones de modelamiento son un subconjunto del núcleo de UML. Construcciones de modelamiento Clases, que modelan metaobjetos MOF. Asociaciones que modelan relaciones binarias entre metaobjetos. Tipos de datos, que modelan tipos primitivos (Integer, String,…) Packages, que modularizan los modelos. Especificaciones en OCL Lenguaje natural
10
Limitaciones de los metamodelos MOF En MDDs, los diferentes lenguajes de modelado y de programación deben definirse en forma consistente y precisa. La semántica de MOF está definida mediante UML/OCL: UML y OCL son imprecisos y ambiguos para verificación, simulación y validación. Si bien OCL es un lenguaje textual su contexto sintáctico está determinado gráficamente OCL no tiene el sólido background de los lenguajes formales
11
Lenguajes formales versus OCL Lenguajes formales Sintaxis Semántica que describe los modelos asociados a la especificación Sistema de inferencia que permite describir deducciones que pueden hacerse desde la especificación formal OCL El contexto sintáctico de OCL está determinado gráficamente. Semántica (notación matemática en un estilo de teoría de conjuntos) No tiene cálculo de pruebas, deducción automatizada
12
Lenguajes formales versus OCL OCL Análisis sintáctico y de tipos. Validación dinámica de invariantes, precondiciones y postcondiciones generando “instantáneas” de un modelo y comparándolas con el modelo especificado. Deducciones lógicas Síntesis y verificación de código
13
Formalización de MOF Para lograr un alto grado de automatización en herramientas CASE la semántica de MOF debería ser precisa Automatizar Formalizar Automatizar Formalizar Formalización de MOF Diagramas estáticos UML Diagramas estáticos UML OCL OCL
14
Formalización de MOF En qué lenguaje? Textual y formal. Textual y formal. Alineado a MOF Alineado a MOF MDD involucra diferentes lenguajes de modelado y de programación que deberían estar alineados con MOF y definidos en forma precisa y consistente.
15
Formalización de MOF Interoperabilidad entre diferentes lenguajes formales Metamodelos MOF Leng.Formales Leng.Programación Lenguaje Formal intermedio Transformaciones automáticas
16
El lenguaje NEREUS
17
El lenguaje de metamodelado NEREUS NEREUS es un lenguaje para especificar metamodelos basados en MOF. NEREUS es un intermediario entre metamodelos MOF y variedad de lenguajes formales y de programación. Las relaciones en NEREUS son entidades de primera clase.
18
El lenguaje de metamodelado NEREUS Construcciones NEREUS CLASES ASOCIACIONES PACKAGES Tipos de datos Tipos predefinidos: OCL Collection, tuple, enumerated,… Tipos constructores para associations
19
NEREUS SINTAXIS CLASS className [ ] IMPORTS INHERITS IS-SUBTYPE-OF ASSOCIATES DEFERRED TYPES FUNCTIONS EFFECTIVE TYPES FUNCTIONS AXIOMS END-CLASS
20
NEREUS Sintaxis CLASS Collection [Elem] IMPORTS Boolean, Nat GENERATED-BY create, add DEFERRED TYPES Collection FUNCTIONS create : Collection add : Collection x Elem Collection count : Collection x Elem Nat iterate : Collection x (Elem x Acc: ANY) x ( -> Acc ) -> Acc EFFECTIVE FUNCTIONS isEmpty: Collection ->Boolean size: Collection Nat
21
NEREUS Sintaxis EFFECTIVE FUNCTIONS isEmpty: Collection ->Boolean size: Collection Nat includes: Collection x Elem ->Boolean includesAll: Collection x Collection ->Boolean excludes: Collection x Elem -> Boolean forAll : Collection X (Elem->Boolean) ->Boolean exists : CollectionX(Elem->Boolean) ->Boolean select: Collection X (Elem->Boolean) -> Collection
22
NEREUS Sintaxis AXIOMS c: Collection; e : Elem; f: Elem->Boolean; g: Elem x Acc-> Acc; base : -> Acc isEmpty ( c ) = (size (c ) = 0 ) iterate (create, g, base ) = base iterate (add (c, e), g, base)= g (e, iterate (c, g, base)) count (c,e) = LET FUNCTIONS f1: Elem x Nat ->Nat AXIOMS e1:Elem; i:Nat f1(e1, i) = if e = e1 then i+1 else i IN iterate (c, f1, 0) END-LET
23
NEREUS Sintaxis AXIOMS c: Collection; e : Elem; f: Elem->Boolean; g: Elem x Acc-> Acc; base : -> Acc … includes (create, e ) = False includes (add (c, e), e1) = if e = e1 then True else includes (c, e1) forAll (create, f ) = True forAll (add(c,e), f ) = f (e) and forAll (c, f) exists (create, f ) = False exists (add (c, e)) = f (e) or exists (c, f ) select (create, f) = create select (add (c,e), f) = if f(e) then add (select(c,f ),e) else select (c, f)… END-CLASS
24
NEREUS Sintaxis AXIOMS c: Collection; e : Elem; f: Elem->Boolean; g: Elem x Acc-> Acc; base : -> Acc … includes (create, e ) = False includes (add (c, e), e1) = if e = e1 then True else includes (c, e1) forAll (create, f ) = True forAll (add(c,e), f ) = f (e) and forAll (c, f) exists (create, f ) = False exists (add (c, e)) = f (e) or exists (c, f ) select (create, f) = create select (add (c,e), f) = if f(e) then add (select(c,f ),e) else select (c, f)… END-CLASS
25
NEREUS: La jerarquía Association Association Aggregation Shared Non- Shared Bidirectional... Binary Association Unidirectional 1..1 *..*
26
NEREUS Especificación de asociaciones ASSOCIATION ASSOCIATION IS [...:Class1;...:Class2; IS [...:Class1;...:Class2;...:Role1;...:Role2;...: mult1;...: mult2;...:visibility1;...:visibility2]...:Role1;...:Role2;...: mult1;...: mult2;...:visibility1;...:visibility2] CONSTRAINED BY CONSTRAINED BY END END
27
CLASS C_Package ASSOCIATES >,... Especificación de asociaciones Ejemplo associationEnd Association End name:String upperbound: Int lowerbound: Int * * Class name:String source 1 * 1 other End Parents Association name:String Package name:String 1 target * 2 1 * association owner 1 owner * 1 nestedpackages * 0..1 Interface 0..* 0..*
28
NEREUS Especificación de asociaciones CLASS C_Package ASSOCIATES >,... ASSOCIATION Class_Package IS Bidirectional-1 [C_Class: class1; C_Package: class2; class: role1; owner: role2; *: mult1; 1: mult2; +: visibility1; +:v isibility2] CONSTRAINED BY… END
29
NEREUS Package PACKAGE packageName IMPORTS IMPORTS INHERITS INHERITS <elements>END-PACKAGE
30
NEREUS Package Core PACKAGE Core CLASS C_Class ASSOCIATES >, >, >, >, >,… FUNCTIONS name: C_Class -> String… END-CLASS CLASS C_Package ASSOCIATES >, >,, > FUNCTIONS name: C_Package -> String… END-CLASS
31
NEREUS Package Core CLASS C_Association… CLASS C_AssociationEnd… CLASS Interface ASSOCIATION A_parents IS Unidirectional-2[C_Class:class1; C_Class:class2; class:role1; parents:role2; 1:mult1; *:mult2; +:visibility1; +: visibility2] END ASSOCIATION A_target… ASSOCIATION Class_Package IS Bidirectional-1 [C_Class: class1; C_Package:class2; class: role1; owner:role2; *:mult1; 1:mult2; +:visibility1;+::visibility2]… END-PACKAGE
32
NEREUS Package Core CLASS C_Association… CLASS C_AssociationEnd… CLASS Interface ASSOCIATION A_parents IS Unidirectional-2[C_Class:class1; C_Class:class2; class:role1; parents:role2; 1:mult1; *:mult2; +:visibility1; +: visibility2] END ASSOCIATION A_target… ASSOCIATION Class_Package IS Bidirectional-1 [C_Class: class1; C_Package:class2; class: role1; owner:role2; *:mult1; 1:mult2; +:visibility1;+::visibility2]… END-PACKAGE
33
Nereus, el lenguaje intermedio Metamodelos MOF Leng.Formales Leng.Programación NEREUS
34
Ejemplo Package Person&Meeting Person name:String Affiliation:String Address:String numMeeting:Nat numConfirmedMeeting ():Nat Meeting title:String start:String end:String isConfirmed:Boolean duration(): Time checkDate (): Bool cancel() numConfirmedParticipants():Nat Participates 2..* * participants meetings Hussmann, H. et al. Abstract Data Types and UML, Report DISI-TR-99-15 P&M
35
OCL Specifications: Person&Meeting context Person:: numMeeting ( ): Nat post: result = self.meetings -> size context Meeting :: isConfirmed (): Bool post: result = self.checkDate() and self.numConfirmedParticipants >= 2 context Meeting:: checkDate():Bool post: result = self.participants->collect(meetings) -> forAll(m | m<> self and m.isConfirmed implies (after(self.end,m.start) or after(m.end,self.start))) context Person :: numMeetingConfirmed ( ) : Nat post: result= self.meetings -> select (isConfirmed) -> size context Meeting :: duration ( ) : Time post: result = timeDifference (self.end, self.start)
36
P&M en NEREUS PACKAGE P&M CLASS Person IMPORTS String, Nat ASSOCIATES > GENERATED-BY Create_Person EFFECTIVE TYPE Person FUNCTIONScreatePerson: String x String x String -> Person name: Person -> String affiliation: Person -> String address: Person -> String set-name: Person x String -> Person set-affiliation : Person x String -> Person set-address: Person x String -> Person AXIOMS p:Person; m: Meeting; s, s1, s2, s3: String; pa: Participates name(createPerson(s1,s2, s3)) = s1 affiliation (createPerson (s1, s2, s3) ) = s2 address (createPerson (s1, s2, s3)) = s3 set-name ( createPerson (s1, s2, s3), s) = createPerson (s,s2,s3)) set-affiliation (createPerson( s1,s2, s3), s) = createPerson (s1, s, s3)) numConfirmedMeetings (p) = size(select m getMeetings(Participates,p), [isConfirmed (m)]) [isConfirmed (m)]) numMeetings (p)= size (getMeetings (Participates, p)) … END-CLASS
37
P&M en NEREUS CLASS Meeting IMPORTS String, Date, Boolean, Time ASSOCIATES > EFFECTIVE TYPE Meeting GENERATED-BY createMeeting FUNCTIONScreateMeeting: String x Date x Date x Boolean- >Meeting tittle: Meeting -> String start : Meeting -> Date end : Meeting -> Date isConfirmed : Meeting -> Boolean set-tittle: Meeting x String -> Meeting set-start : Meeting x Date -> Meeting set-end: Meeting x Date -> Meeting set-isConfirmed: Meeting x Boolean -> Boolean AXIOMS s: String; d, d1,: Date; b: Boolean;… title( createMeeting (s, d, d1, b) ) = s start ( createMeeting (s, d, d1, b)) = d end ( createMeeting (s, d, d1, b)) = d1 isConfirmed(createMeeting(s,d,d1,b)) = b...END-CLASS ASSOCIATION Participates IS Bidirectional-Set [Person: Class1; Meeting: Class2; participants: Role1; meetings: Role2; *: Mult1; * : Mult2; + : Visibility1; +: Visibility2] ENDEND-PACKAGE
38
Ejemplo P&M Asociación Bidirectional-Set RELATION SCHEME Bidirectional-Set INHERITS BinaryAssociation [Class1 ->Person, Class2->Meeting] IMPORTS Set_Person: Set [Person], Set_Meeting: Set[Meeting] EFFECTIVE FUNCTIONS name, frozen, changeable, addOnly, getRole1, getRole2, getMult1, getMult2, getVisibility1, getVisibility2, isRelated, isEmpty, rightCardinality, leftCardinality create: Typename->Participates addLink:Participates(b) x Person(p) x Meeting(m)-> Participates pre: not isRelated(a,p,m) isRightLinked: Participates x Person -> Boolean isLeftLinked: Participates x Meeting -> Boolean getMeetings: Participates(a) x Person(p) -> Set_Meeting pre: isRightLinked(a,p) getParticipants: Participates(a) x Meeting(m)-> Set_Person pre: isLeftLinked(a,m) remove: Participates (a) x Person (p) x Meeting (m) -> Participates pre: isRelated(a,p,m)
39
Ejemplo P&M Asociación Bidirectional-Set AXIOMS a:Participates; p,p1: Person; m,m1:Meeting; t:TypeName name(create(t))= t name(add(a,p,m)) = name(a) isEmpty (create(t))= True isEmpty(addLink(a,p,m))= False frozen (a) = False changeable (a)= True addOnly (a) = False getRole1(a) = “ participants” getRole2 (a) = “meetings” getMult1(a) = * getMult2(a) = * getVisibility1(a) = + getVisibility2(a) = +
40
Ejemplo P&M Asociación Bidirectional-Set isRelated (create(t),p,m) = False isRelated(addLink(a,p,m),p1,m1) = (p=p1 and m=m1) or isRelated (a,p1,m1) isRightLinked (create(t),p) = False isRightLinked (addLink (a,p,m),p1)= if p=p1 then True else isRightLinked(a,p1) rightCardinality(create(t),p)= 0 rightCardinality(addLink(a,p,m),p1) = if p=p1 then 1 + rightCardinality(a,p1)else rightCardinality(a,p1) getMeetings(addLink(a,p,m),p1)= if p=p1 then including (getMeetings(a,p1), m)else getMeetings(a,p1) getParticipants (addLink (a,p,m),m1) = if m=m1 then including (getParticipants(a,m1), m) else getParticipants(a,m1) END-RELATION
41
Traducción de metamodelos MOF
42
Formalizando modelos estáticos UML.Traducción de Packages
43
Formalizando modelos estáticos UML. El esquema BOX CLASS Name IMPORTS TP1,..., TPm, T-attr1, T-attr2,..., Tattrn INHERITS B1,B2,..., Bm ASSOCIATES >,..., >, >,..., >, >,..., > >,..., >EFFECTIVE TYPE Name FUNCTIONS createName : T-attr1 x... x T-attrn -> Name set i : Name x T-attri -> Name get i : Name -> T-attri 1 T-attri 1<=i<=n
44
Formalizando modelos estáticos UML. El esquema BOX DEFERRED FUNCTIONS meth1: Name x TPi1 x TPi2 x TPin -> TPij... methr : Name x TPr1 x TPr2... x TPin -> TPij AXIOMS t1,t1’: T-attr1; t2,t2’:T-attr2;...; tn,tn’:T-attrn geti(create(t1,t2,...,tn)) = ti 1 i n seti (create (t1,t2,...,tn), ti’) = create (t1,t2,...ti’,...,tn) END-CLASS
45
Formalizando modelos estáticos UML. El esquema Association ASSOCIATION ___ IS __ [__: Class1; __:Class2; __: Role1;__:Role2; __:Mult1; __:Mult2; __:Visibility1; __:Visibility2] CONSTRAINED BY __ END
46
Un puente entre UML/OCL y NEREUS Un sistema de reglas de transformación para traducir Tipos OCL predefinidos Expresiones básicas OCL Precondiciones Postcondiciones Invariantes Constraints de asociaciones
47
Reglas OCL/NEREUS v. operation(v’) v->operation (v’) operation (v,v’) v.attribute attribute (v ) context A object.rolename getRolename (A, object) e.op op (Translate NEREUS ( e)) collection-> op (v:Elem |b-expr-with-v) op ::=select| forAll| reject| exists LET FUNCTIONS f: Elem ->Boolean AXIOMS v : Elem f(v)= Translate NEREUS (b-expr-with-v ) IN op (collection, f) END-LET ---------------------------------------------- op v (collection,[f(v)]) concise notation T Op ( parameterList ):ReturnType post: expr AXIOMS t : T,... Translate NEREUS (exp) OCLNEREUS
48
Reglas OCL/NEREUS
54
Desde OCL a NEREUS Traducción de una postcondición context Person :: numMeetingConfirmed ( ) : Nat OCL post: result= self.meetings -> select (isConfirmed) -> size T Op ( parameterList ) : ReturnType post: result = expr AXIOMS t:T,... Op (t, parameterList ) = Translate NEREUS (expr) T-> select (v :Type | boolean-expr-with-v) select v (Translate NEREUS (T), Translate NEREUS (boolean-expr-with-v) NEREUS AXIOMS p:Person; m:Meeting;Pa:Participates;… numMeetingsConfirmed (p) = size(select m (getMeetings(Pa,p), isConfirmed [m]) RULE 2 RULE 1 RULES 1,2,..
55
Traducción de P&M a NEREUS
56
1.Generar una especificación parcial de Person y Meeting a partir de la instanciación de BOX. 2.Generar una especificación de Participates instanciando el esquema Association. 3.Transformar especificaciones OCL a partir del sistema de transformaciones. 4.Generar el Package P&M que incluye a las clases Person y Meeting y una asociación, Participates.
57
Traducción de P&M a NEREUS La clase Person CLASS Person IMPORTS String, Nat ASSOCIATES > GENERATED-BY create_Person DEFERRED TYPES Person FUNCTIONS create_Person: String x _-> Person EFFECTIVE FUNCTIONS name: Person -> String numMeetings: Person -> Nat numConfirmedMeeting: Person -> Nat set-name: Person x String -> Person set-numMeetings: Person x Nat -> Person set-numConfirmedMeeting: Person x Nat -> Person AXIOMS p:Person; m:Meeting; s,s’: String name(create_Person(s))= s set-name(create_Person(s), s’) = create_Person (s’) END-CLASS PASO 1
58
Traducción de P&M a NEREUS La clase Meeting CLASS Meeting IMPORTS String, Date, Boolean, Time ASSOCIATES > GENERATED-BY create_Meeting DEFERRED TYPES Meeting FUNCTIONS create_Meeting: String x Date x Date x Boolean -> Meeting EFFECTIVE … isConfirmed: Meeting -> Boolean … AXIOMS s, s’:String; d, d’, d1, d1’:Date; b, b’:Boolean title (create_Meeting (s,d,d1,b)) = s start (create_Meeting (s,d,d1,b)) = d end (create_Meeting (s,d,d1,b)) = d1 set-tittle (create_Meeting (s,d,d1,b),s’) = create_Meeting (s’,d,d1,b) set-start(create_Meeting (s,d,d1,b),d’) = create_Meeting (s,d’,d1,b) set-end(create_Meeting (s,d,d1,b),d1’) = create_Meeting (s,d,d1’,b) END-CLASS
59
Traducción de P&M a NEREUS La asociación Participates ASSOCIATION Participates IS Bidirectional-Set [ Person: Class1; Meeting: Class2; participants: Role1; meetings:Role2; *:Mult1; *: Mult2; +: Visibility1; +: Visibility2] END RELATION SCHEME Bidirectional-Set -- Bidirectional /* to */ as Set IS-SUBTYPE-OF BinaryAssociation [Person:Class1; Meeting:Class2]…
60
Traducción de P&M a NEREUS La clase Person CLASS Person IMPORTS String, Nat ASSOCIATES > GENERATED-BY create_Person... AXIOMS p: Person; s, s’: String; Pa: Participates name (create_Person(s)) = s set-name (create_Person(s), s’) = create_Person(s’) numConfirmedMeetings (p) = size(selectm (getMeetings(Pa,p), [isConfirmed (m)] ) Reglas 10,15 numMeetings (p) = size (getMeetings (Pa, p)) Reglas 10 END-CLASS PASO 3
61
Traducción de P&M a NEREUS La clase Meeting Traducción de P&M a NEREUS La clase Meeting CLASS Meeting AXIOMS m,m1:Meeting; s,s’:String; d,d’,d1,d1’:Date; Pa:Participates;… title (create_Meeting(s,d,d1,b)) = s start (create_Meeting(s,d,d1,b)) = d end (create_Meeting(s,d,d1,b)) = d1 set-tittle (create_Meeting(s,d,d1,b),s’) = create_Meeting(s’,d,d1,b) set-start(create_Meeting(s,d,d1,b),d’) = create_Meeting(s,d’,d1,b) set-end(create_Meeting(s,d,d1,b),d1’) = create_Meeting(s,d,d1’,b) duration (m) = timeDifference (end(m),start(m)) Regla 10 isConfirmed (cancel(m)) = False isConfirmed (m)=checkDate(m) and NumConfirmedParticipants (m) >= 2 checkDate(m) = forAll me (collect p (getParticipants(Pa,m), [getMeetings (Pa, p)]), [consistent(m,me)] ) [getMeetings (Pa, p)]), [consistent(m,me)] ) consistent(m,m1)= not (isConfirmed(m1)) Reglas 10,15,16 or (end(m)<start(m1) or end(m1)<start(m)) NumConfirmedParticipants (m) = size (getParticipants(Pa,m)) NumConfirmedParticipants (m) = size (getParticipants(Pa,m))END-CLASS
62
Traducción de NEREUS a LOO
63
Desde NEREUS a EIFFEL
64
Traducción de clases CLASS Name [ ] clase Eiffel IMPORTS relación cliente IS-SUBTYPE-OF IS-SUBTYPE-OF INHERITS herencia DEFERRED TYPES TYPES FUNCTIONS feature diferidos precondiciones EFFECTIVE TYPES TYPES FUNCTIONS feature efectivo precondiciones precondiciones AXIOMS postcondiciones invariantes END-CLASS
65
Generación de contratos EIFFEL Transformación de precondiciones Transformación de precondiciones Transformación de axiomas Transformación de axiomas Heurística para generar invariantes Heurística para generar postcondiciones Heurística para generar implementaciones
66
Construcción de invariantes Heurística Identificar correspondencias entre los términos de un axioma y los “features” de una clase que sólo dependan del estado actual del objeto. Un axioma puede traducirse a un invariante si los únicos subtérminos del “tipo de interés” que existen son variables.
67
Construcción de invariantes Un ejemplo CLASS BSTACK G ....EFFECTIVE TYPES BSTACK FUNCTIONS capacity:BSTACK Integer count: BSTACK Integer full: BSTACK Boolean empty:BSTACK Boolean...... AXIOMS s: BSTACK; s: G full(s) (capacity(s) = count(s) ) empty(s) (count(s)=o) END-CLASS class BSTACK G ..... capacity:INTEGER.... count:INTEGER... full:BOOLEAN... empty:BOOLEAN... invariant full= (count=capacity); empty= (count =0)..... end
68
Construcción de postcondiciones Heurística Identificar en un axioma un término op( ) donde op es el nombre de una operación y contiene una variable del tipo de interés y todos los restantes términos dependen solamente de constantes o las restantes variables de op( ) donde op es el nombre de una operación y contiene una variable del tipo de interés y todos los restantes términos dependen solamente de constantes o las restantes variables de Si op( ) es un término del “tipo de interés” se lo asocia a Current y la variable del “tipo de interés” a old Si op( ) no es un término del tipo de interés se lo asocia a Result
69
Construcción de postcondiciones: Un ejemplo CLASS SET G ...EFFECTIVE TYPES SET FUNCTIONS has: SET x G BOOLEAN count: SET INTEGER extend: SET x G SET empty: SET BOOLEAN AXIOMS s:SET; v:G has(s,v) not empty(s) count(extend(s,v)) = if has(s,v) then count(s) else plus(count(s),1) END-CLASS END-CLASS class SET G .... empty:BOOLEAN has(v:G):BOOLEAN....... ensure Result implies not empty...... extend( v: G).................. ensure old has(v) implies count=old count not old has(v) Implies (count=old count + 1)
70
Traducción de asociaciones El componente Association
71
Traducción de asociaciones P&M
76
Traducción de NEREUS a Lenguajes Formales
77
Desde NEREUS a lenguajes formales Se seleccionó como lenguaje formal a CASL (Common Algebraic Specification Language) Lenguaje de especificación algebraica de propósito general Tiene una definición semántica sólida Es soportado por herramientas Facilita interoperabilidad con otros prototipos y herramientas “formales”
78
Traducción de NEREUS a CASL Clases Clases Relaciones Herencia Cliente Funciones Higher-order Visibilidad AsociacionesPackages
79
Traducción de asociaciones NEREUS/ CASL Paso 1: Reagrupar las operaciones de las clases A y B distinguiendo operaciones locales a A y a B y locales a A, B y Assoc. A B Assoc LOCAL OPERACIONES /ATRIBUTOS Personname Meetingtittle, start, end, duration Person, Meeting, Participatescancel,isConfirmed, numConfirmedMeetings, checkDate, numMeetings
80
Traducción de asociaciones NEREUS/ CASL spec PERSON given STRING, NAT = then generated type Person ::= create-Person (String) ops name: Person -> String setName :Person x String -> Name end spec MEETING given STRING, DATE = then generated type Meeting ::= create-Meeting ( String; Date; Date) Ops tittle: Meeting -> String set-title: Meeting x String -> Meeting start : Meeting -> Date set-start: Meeting x Date -> Meeting isEnd: Meeting -> Date set-end: Meeting x Date -> Meeting end Paso 2: Construir las especificaciones C y D a partir de A y B donde C y D incluyen operaciones locales a A y B respectivamente
81
Traducción de asociaciones NEREUS/CASL spec SET-PERSON given NAT= PERSON and BAG[PERSON] and … then generated type Set[Person] :: = create | including (Set[Person]; Person) ops union : Set[Person] x Set[Person] -> Set [Person] intersection : Set[Person] x Set[Person] -> Set [Person] count: Set[Person] x Person -> Nat … spec SET-MEETING given NAT = MEETING and BAG[MEETING] and … then generated type Set [Meeting] :: = create | including (Set[Meeting]; Meeting) … Paso 3: Construir las especificaciones Collection[C] y Collection [D] a partir de esquemas reusables
82
Traducción de asociaciones NEREUS/CASL spec PARTICIPATES = SET-PERSON and SET-MEETING and BINARY-ASSOCIATION [PERSON][MEETING] with BinaryAssociation|-> Participates pred isRightLinked: Participates x Person isLeftLinked: Participates x Meeting isRelated: Participates x Person x Meeting ops addLink: Participates x Person x Meeting -> Participates getParticipants: Participates x Meeting -> Set [Person] getMeetings: Participates x Person -> Set[Meeting] remove: Participates x Person x Meeting -> Participates a : Participates; p,p1: Person; m,m1: Meeting def addLink (a,p,m) not isRelated (a,p,m) def getParticipants (a, m) isLeftLinked (a,m) def getMeetings (a, m) isRightLinked ( a, m) def remove (a,p,m) isRelated (a, p, m) end Paso 4: Construir una especificación Assoc (con Collection[C] y Collection[D]) instanciando esquemas reusables en el Collection[D]) instanciando esquemas reusables en el componente Association componente Association
83
Traducción de asociaciones NEREUS/CASL spec PERSON&MEETING = PARTICIPATES then ops numMeeting : Participates x Person -> Nat numConfirmedMeeting : Participates x Person -> Nat isConfirmed : Participates x Meeting -> Boolean numConfirmedParticipants: Participates x Meeting -> Nat checkDate: Participates x Meeting -> Participates select : Participates x Set[Meeting] -> Set[Meeting] collect: Participates x Set[Person] -> Bag[Meeting] pred forall: Participates x Set[Meeting] x Meeting Paso 5: Construir la especificación AssocA+B extendiendo Assoc con C, D y las operaciones locales a C, D y Assoc. con C, D y las operaciones locales a C, D y Assoc.
84
Traducción de asociaciones NEREUS/CASL s : Set[Meeting]; m:Meeting; pa:Participates; p:Person; m:Meeting; sp:Set[Person]; bm: Bag[Meeting] forall (pa, including(s,m),m1) = isConsistent(m,m1) and forall(pa, s, m1) select(pa, create-Meeting) = create-Meeting select (pa, including (s,m)) = including(select(s,pa),m) when isConfirmed (pa, m) else select (s,pa) collect (pa, create-Person,s) = asBag (create-Person) collect (pa, including (sp, p) ) = asBag (including (collect (pa,sp), p)) numMeeting( pa, p) = size (getMeetings(pa, p)) isConfirmed (pa, m)=checkDate (pa,m) and NumConfirmedParticipants(pa,m) >2 numConfirmedMeeting (pa, p) = size (select (getMeetings (pa,p)) checkDate (pa, m) = forall (pa, collect (getParticipants(pa,m), m) isConsistent (pa, m, m1) = not (isConfirmed (pa,m1)) or (end(m) < start (m1) or end (m1) < start(m)) numParticipantsConfirmed (pa, m) = size( getParticipants (pa, m)) end Paso 5:
85
Traducción de asociaciones NEREUS/CASL Person&Meeting Participates SetPerson SetMeeting Person Meeting name tittle start end duration getMeetings getParticipates forAll select collect numMeetings numConfirmedMeetings isConfirmed checkDate cancel
86
Especificando transformaciones en NEREUS
87
Un “Megamodelo”de componentes para MDA PIM Metamodel Postcondition Parameters Precondition Postcondition Refinement PIM-PSM * * source 1 PSM Metamodel 1 * target ISM Metamodel Refinement PSM-ISM * * source 1 * target 1 * Postcondition Parameters Precondition Postcondition
88
“Megacomponentes”: El patrón Observer “Megacomponentes”: El patrón Observer Observer Pattern PIM Metamodel UML/OCL Refinement PIM to PSM EIFFEL Refinement PIM to PSM J2EE Observer Pattern PSM Metamodel J2EE Observer Pattern ISM Metamodel EIFFEL Observer Pattern ISM Metamodel JAVA Refinement PSM Eiffel to ISM Eiffel Refinement PSM J2EE to ISM JAVA Observer Pattern PSM Metamodel EIFFEL Observer Pattern PSM Metamodel.NET Observer Pattern ISM Metamodel C# Refinement PSM.NET to ISM C# Refinement PIM to PSM.NET “megacomponente”: instancia del “megamodelo”
89
Metamodel 1 Postcondition Precondition Postcondition Transformation Metamodel 2 CLASS name [metamodelName1:source; metamodelName2: target] GENERATED-BY create, addLink EFFECTIVE TYPE name FUNCTIONS create: -> name addLink: name (t) x metamodelName1 (m1) x metamodelName2 (m2) -> name pre: Translate NEREUS (Transformation.precondition) remove: name (t) x metamodelName1 (m1) x metamodelName2 (m2) -> name pre: isRelated (t, m1, m2) isRelated: name x metamodelName1 x metamodelName2 -> Boolean isEmpty: name -> Boolean get_Pim: name (t)-> metamodelName1 pre: not isEmpty (t) get_Psm: name (t)-> metamodelName2 pre: not isEmpty (t) AXIOMS t:name; m1,m3:metamdoelName1; m2,m4:metamodelName2 isRelated(t, m1, m2) implies Translate NEREUS (Transformation.postcondition) …END-CLASS Un esquema de transformación para refinamientos
90
CLASS PimUmlToPsmEiffel [ObserverMetamodel : source; ObserverMetamodelEiffel : target]... FUNCTIONS create: -> PimUmlToPsmEiffel addLink: PimUmlToPsmEiffel (t) x ObserverMetamodel (m1) x ObserverMetamodelEiffel (m2) -> PimUmlToPsmEiffel pre: isEmpty(get_importedElements(ElementImport-PackageableElement, m1) isRelated: PimUmlToPsmEiffel x ObserverMetamodel x ObserverMetamodelEiffel -> Boolean... AXIOMS t : PimUmlToPsmEiffel, m1: ObserverMetamodel, m2: ObserverMetamodelEiffel isRelated(t,m1,m2) implies size( select s (get_ownedElement(Element-Element,m1), [oclIsTypeOf(Class,s) or oclIsTypeOf(Interface, s)] ) = size(select e (get_ownedElement(Element-Element,m2), [oclIsTypeOf(EiffelClass,e)]) and forAll sourceClass (select source (get_ownedElement(Element-Element,m1), [exists targetClass (select tc (get_ownedElement(Element-Element), m2), [oclIsTypeOf(EiffelClass, tc)]), [name(sourceClass) = name(targetClass) and…... END-CLASS Formalización de refinamientos
91
Resumen Metamodelos MOF Leng.Formales Leng.Programación Lenguaje NEREUS Transformaciones automáticas
92
Resumen NEREUS provee las ventajas de un lenguaje intermedio NEREUS provee las ventajas de un lenguaje intermedio Es textual, alineado con MOF Es textual, alineado con MOF Metamodelos Metamodelos Gramáticas Gramáticas Interoperabilidad a nivel de lenguajes Interoperabilidad a nivel de lenguajes Semántica “más precisa” de UML 2.0 y OCL 2.0 Semántica “más precisa” de UML 2.0 y OCL 2.0 Traducciones “constructivas” que permiten automatización Traducciones “constructivas” que permiten automatización
Presentaciones similares
© 2024 SlidePlayer.es Inc.
All rights reserved.