Last active
August 29, 2015 14:10
-
-
Save pedrogk/6550a1f8e08c7fbbff5f to your computer and use it in GitHub Desktop.
Listado 1. Aplicación de aspectos y DbC con Ptolemy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// El evento se notifica cuando Entero cambia | |
void event IntEvento { | |
// variables de contexto | |
int x,y; | |
// Contrato translúcido. Iniciamos con precondición. | |
requires x < 25 && y < 120 | |
assumes { | |
next.invoke(); | |
establishes next.x() == old(next.x()); | |
} | |
ensures x < 25 | |
// Cerramos con postcondición. | |
} | |
public class Entero { | |
Entero() { | |
// Registra el evento en la lista de los objetos activos. | |
register(this); | |
} | |
public void aviso(IntEvento next) throws Throwable { | |
next.invoke(); | |
// Refinamiento contrato translúcido | |
refining establishes next.x() == old(next.x()) { | |
System.out.println("Valor x: "+ next.x() + "\nValor y:"+next.y()); | |
} | |
} | |
when IntEvento do aviso; | |
void metodo() { | |
// activación del aspecto | |
announce IntEvento(20,119) { | |
System.out.println("Hola!! cumplo el contrato traslucido"); | |
} | |
announce IntEvento(200,12) { | |
System.out.println("No cumplo el contrato translúcido"); | |
} | |
} | |
public static void main(String[]args) { | |
new Entero().metodo(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment