Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Overall
presenta3on




                  Introduc3on
to
Domain
Specific
Languages
and

                       its
techniqu...
Domain
Specific
Language
(DSL)
is
a

                  programming
language
dedicated
to

                  solve
problems
...
which
can
be
technical


                  
  SQL

                  
  HQL

                  
  CSS

www.devoxx.com

or
business
related.

                  
  Banking

                  
  Manufacturing

                  
  Logis3cs

www...
A
DSL
can
be
internal
or
external.

www.devoxx.com

External
DSLs
are
self‐contained

www.devoxx.com

while
internal
DSLs
remain
on
top
of

         other
programming
languages.

www.devoxx.com

In
other
words,
internal
DSLs
are
APIs.

www.devoxx.com





                  That's why they're also known as Fluent Int...
DSLs
allow
you
to
express
domains
clearly.

www.devoxx.com

For
example,
while
a
business
analyst
of

         a
banking
domain
would
say




Transfer 5.000,00 from Client A's cash a...
A
common
JAVA
implementa3on
could
be



                  bankService.transfer(5000.00,
                                  ...
An
external
DSL
could
express
the
same
as




                  transfer 5000 from clientA.cashAccount to clientB.savingsA...
And
an
internal
DSL
in
JAVA
could
look
like



                  bankService.execute( new Transfer()
                     ...
It’s
not
about
one
single
method



                     public
Transfer
of(double
value);

www.devoxx.com

but
an
en3re
meaningful
opera3on.



         new Transfer()
                    .of(5000)
                    .from(clien...
Some
techniques
to
define
internal
DSLs

www.devoxx.com

Method
Chaining




                  new Transfer()
                             .of(5000)
                             ....
Nested
Func3on




                  bankService.transfer(5000,
                                     from(clientA.cashAcco...
Object
Scoping


                  bankService.execute(
                             new Transfer(){{
                    ...
Fluent
Valida3on
Framework
is
a
lab

                  project
applying
Fluent
Interfaces
to
the

                        ...
Main
idea
was
changing
valida3ons
like




                  if(arg0 == null)
                       throw new IllegalArgu...
to
something
like




                       ensure(arg0).isNotNull();
www.devoxx.com

How
to
change
excep3on
message?




                  ensure(arg0).isNotNull().otherwise("arg0 cannot be null");
         ...
Trigger
method
at
the
end
of
the
expression



                    ensure(arg0).isNotNull().now();

                    en...
Another
op3on
was
crea3ng
two
entry
points



                  ensure(arg0).isNotNull();

                  analyse(arg0)...
Mixing
method
chaining
with
nested
func3ons




                  ensure(myObject).is(inValidState());

                  ...
Today
we
saw


                  
    DSLs
are
cool!

                  
     External
DSLs
are
hard
to
implement

       ...
That’s
all
folks!

                  
    project
hXp://fluval.sourceforge.net

                  
     blog
hXp://blog.dan...
Fluent Validation Framework - A DSL for validations using fluent interfaces
Upcoming SlideShare
Loading in …5
×

Fluent Validation Framework - A DSL for validations using fluent interfaces

3,719 views

Published on

Published in: Technology, Business
  • Be the first to comment

Fluent Validation Framework - A DSL for validations using fluent interfaces

  1. 1. Overall
presenta3on
 Introduc3on
to
Domain
Specific
Languages
and
 its
techniques.
As
well
as
showing
Fluent
 Valida3on
Framework
concep3on
process.

 www.devoxx.com

  2. 2. Domain
Specific
Language
(DSL)
is
a
 programming
language
dedicated
to
 solve
problems
of
an
specific
domain
 www.devoxx.com

  3. 3. which
can
be
technical

  SQL
  HQL
  CSS
 www.devoxx.com

  4. 4. or
business
related.
  Banking
  Manufacturing
  Logis3cs
 www.devoxx.com

  5. 5. A
DSL
can
be
internal
or
external.
 www.devoxx.com

  6. 6. External
DSLs
are
self‐contained
 www.devoxx.com

  7. 7. while
internal
DSLs
remain
on
top
of
 other
programming
languages.
 www.devoxx.com

  8. 8. In
other
words,
internal
DSLs
are
APIs.
 www.devoxx.com
 That's why they're also known as Fluent Interfaces!

  9. 9. DSLs
allow
you
to
express
domains
clearly.
 www.devoxx.com

  10. 10. For
example,
while
a
business
analyst
of
 a
banking
domain
would
say
 Transfer 5.000,00 from Client A's cash account to Client B's savings account.
 www.devoxx.com

  11. 11. A
common
JAVA
implementa3on
could
be
 bankService.transfer(5000.00, clientA.getCashAccount(), clientB.getSavingsAccount());
 www.devoxx.com

  12. 12. An
external
DSL
could
express
the
same
as
 transfer 5000 from clientA.cashAccount to clientB.savingsAccount
 www.devoxx.com

  13. 13. And
an
internal
DSL
in
JAVA
could
look
like
 bankService.execute( new Transfer() .of(5000) .from(clientA.cashAccount()) .to(clientB.savingsAccount()));
 www.devoxx.com

  14. 14. It’s
not
about
one
single
method
 public
Transfer
of(double
value);
 www.devoxx.com

  15. 15. but
an
en3re
meaningful
opera3on.
 new Transfer() .of(5000) .from(clientA.cashAccount()) .to(clientB.savingsAccount()) www.devoxx.com

  16. 16. Some
techniques
to
define
internal
DSLs
 www.devoxx.com

  17. 17. Method
Chaining
 new Transfer() .of(5000) .from(clientA.cashAccount()) .to(clientB.savingsAccount()) www.devoxx.com

  18. 18. Nested
Func3on
 bankService.transfer(5000, from(clientA.cashAccount()), to(clientB.savingsAcount())); www.devoxx.com

  19. 19. Object
Scoping
 bankService.execute( new Transfer(){{ of(5000); from(clientA.cashAccount()); to(clientB.savingsAccount()); }}); www.devoxx.com

  20. 20. Fluent
Valida3on
Framework
is
a
lab
 project
applying
Fluent
Interfaces
to
the
 domain
of
code
valida3on.
 www.devoxx.com

  21. 21. Main
idea
was
changing
valida3ons
like
 if(arg0 == null) throw new IllegalArgumentException(); www.devoxx.com

  22. 22. to
something
like
 ensure(arg0).isNotNull(); www.devoxx.com

  23. 23. How
to
change
excep3on
message?
 ensure(arg0).isNotNull().otherwise("arg0 cannot be null"); //doesn't work www.devoxx.com

  24. 24. Trigger
method
at
the
end
of
the
expression
 ensure(arg0).isNotNull().now(); ensure(arg0).isNotNull() .otherwise() .throwThis( new IllegalStateException()) .now(); //not cool! www.devoxx.com

  25. 25. Another
op3on
was
crea3ng
two
entry
points
 ensure(arg0).isNotNull(); analyse(arg0).and().throwThis(new IllegalStateException()).ifNull(); www.devoxx.com

  26. 26. Mixing
method
chaining
with
nested
func3ons
 ensure(myObject).is(inValidState()); analyse(systemReport).and(notifyByEmail()).ifIsNot(operatingWell()); www.devoxx.com
 the
solu3on
became
extensible!


  27. 27. Today
we
saw
  DSLs
are
cool!
  External
DSLs
are
hard
to
implement
  Fluent
Interfaces
and
Internal
DSLs
are
the
same
thing
  Fluent
Interfaces
work
great
for
extensively
used
APIs
 www.devoxx.com

  28. 28. That’s
all
folks!
  project
hXp://fluval.sourceforge.net
  blog
hXp://blog.danielgazineu.com
  email/gtalk
danielgazineu@gmail.com
  twiXer
@danielgazineu
 www.devoxx.com


×