DjangoCon US 2011

Hey! Although I have been more actively around Ruby for the last two years and I’m still doing some more stuff with Rails, I’m getting up to speed with the python world. I’m quite excited that I will be able to go to DjangoCon this week in Portland, OR. Django and its community has been maturing a lot in the last couple of years. There are a lot of libraries and a lot of things happening around it. One of the cool projects is Nose and django-nose; it makes easy to run and write tests looking for TestCase subclasses in your project’s tree.

Object Constraint Language (OCL)

OCL es un lenguaje para expresar invariantes en Modelos de Dominio con UML.

Ventajas al usarlo

  • la restriccion se puede especificar precisamente
  • pueden ser procesadas automaticamente

Desventajas

  • el lenguaje puede ser un poco complejo
  • requiere aprender las construcciones del lenguaje

Lenguaje tipado

  • Cada clase definida en el modelo representa un tipo en OCL.
  • Las propiedades de los objetos se acceden mediante ‘.’
  • Tiene Integer, String y operaciones de colecciones
  • Una propiedad es un atributo, extremo de asociacion (se usa el rol), operacion sin efectos.

Operaciones sobre Collections (Set, Bag, Sequence)

collection->size() : Integer
collection->includes(o:OclAny) : Boolean
collection->isEmpty() : Boolean
collection->exists(e:OclExpression) :Boolean

Ejemplos

Unicidad de atributos

“No hay dos productos con el mismo codigo”
context Product inv:
Product.allInstances->forAll(p1,p2:Producto | p1<>p2 implies p1.codigo<>p2.codigo)

Dominio de atributos

“En la empresa no puede haber vendedores mayores de 65 anios”
context Empresa inv:
self.Vendedor->select(v:Vendedor | v.edad >65)->isEmpty()

Integridad circular

“Un vendedor no puede vender productos de una empresa en la que no trabaja”
context Vendedor inv:
self.empresa.producto->includes(self.producto)

Atributos calculados

“El atributo cantEmp es la cantidad de empleados de la empresa”
context Empresa inv:
self.cantEmp = self.vendedor->size()

Reglas de negocio

“Ningun vendedor menor de 30 anios puede vender el producto de codigo X”
context Empresa inv:
let vends:Sets(vendedor) = self.vendedor -> select(v:vendedor | v.edad >30)
in vends->forAll(v:Vendedor | v.producto.codigo<>X)