Features · Business Rules in OCL
Business Rules modeling in BESSER.
Define, validate and enforce Object Constraint Language constraints directly on your B-UML models. Write an invariant or pre/post condition once; B-OCL parses it, checks it against your object model, and propagates it into every generated artifact automatically.
editor.besser-pearl.org — OCL constraints
See it in action
One constraint. Multiple outputs.
The same OCL invariant, defined once at the B-UML structural model level, rendered as executable enforcement logic for Pydantic (left) and Django (right).
pydantic.py
class Book(BaseModel):
release: date
genre: Genre
price: float
pages: int
title: str
stock: int
id: int # id created
authors: List[int] # N:M Relationship
library: List[int] # N:M Relationship
@field_validator('pages')
@classmethod
def validate_pages_1(cls, v):
"""OCL Constraint: book_positive_pages"""
if not (v > 0):
raise ValueError('pages must be > 0')
return v
django.py
class Book(models.Model):
"""
Represents a book in the system.
"""
title = models.CharField(max_length=255)
pages = models.IntegerField()
stock = models.IntegerField()
price = models.FloatField()
release = models.DateField()
genre = models.CharField(max_length=255, choices=Genre.choices)
authors = models.ManyToManyField(
'Author', related_name='books')
library = models.ManyToManyField(
'Library', related_name='books')
class Meta:
verbose_name = "Book"
verbose_name_plural = "Books"
def __str__(self):
"""
Returns a string representation of the book.
"""
return str(self.title)
def clean(self):
"""
Validates the OCL constraints defined on Book.
"""
super().clean()
errors = {}
if not (self.pages > 0):
errors.setdefault('pages', []).append('pages must be > 0')
if errors:
raise ValidationError(errors)
Capabilities
Everything you need to model, validate and enforce OCL constraints.
Walkthrough
Watch it end to end
Write an OCL constraint on a class diagram, trigger the Quality Check to validate it against an object model.
editor.besser-pearl.org — define → validate