Wednesday, August 29, 2012

Bookmark and Share

Note: This post originally appeared on beanvalidation.org. Please post any feedback over there.

Now that everybody is returning from their summer holidays, also the Bean Validation team is getting back to their desks in order to work with full steam towards revision 1.1.

As you know, the largest new feature will be method validation, that is the validation of method parameters and return values using constraint annotations. Bean Validation 1.1 early draft 1 lays the ground for this, and right now we're tackling some advanced questions still open in that area (btw. if you haven't yet tried out the reference implementation of ED1, this is the perfect time to do so and give us your feedback).

The problem

One question the EG currently is discussing is whether and, if so, how a refinement of method constraints should be allowed in sub-types. That is, if a class implements a method of an interface or overrides a method from a super class, should the sub-type be allowed to place any additional constraints?

The current draft defines the following rules for such cases (see the draft document for all the gory details):

  • No parameter constraints may be specified in addition to those constraints defined on the method in the interface or super class.
  • Return value constraints may be added in sub-types.

The rationale

The rationale behind this is the principle of behavioral sub-typing, which demands that wherever a given type T is used, it should be possible to replace T with a sub-type S of T. This means that a sub-type must not strengthen a method's preconditions (by adding parameter constraints), as this might cause client code working correctly against T to fail when working against S. A sub-type may also not weaken a method's postconditions. However, a sub-type may strengthen the method's postconditions (by adding return value constraints), as client code working against T still will work against S.

Can you show me some code, please?

To give you an example, the following shows a constraint declaration considered illegal as of the current draft, as parameter constraints are added to the placeOrder() method in a sub-class of OrderService:

1
2
3
4
5
6
7
8
9
10
11
12
public class OrderService {
    void placeOrder(@NotNull String customerCode, @NotNull Item item, int quantity) { ... }
}

public class SimpleOrderService extends OrderService {

    @Override
    public void placeOrder(
        @Size(min=3, max=20) String customerCode,
        Item item,
        @Min(1) int quantity) { ... }
}

Alternatives

While this approach works, follows principles of clean OO design and also is employed by other Programming by Contract solutions, some voices in the EG expressed doubts whether the handling of parameter constraints isn't too restrictive and thus may limit innovation in that area. In particular with respect to legacy code, the question was raised whether it shouldn't be allowed to add parameter constraints in sub-types.

One example may be a legacy interface, which technically has no constraints (that is, no parameter constraints are placed on its methods), but comes with a verbal description of preconditions in its documentation. In this case an implementor of that interface might wish to implement this contract by placing corresponding constraint annotations on the implementation.

An open question in this situation is what should the behavior be if the interface is being constrained afterwards?

Give use your feedback!

So what do you think, should such a refinement of parameter constraints be allowed or not? Possible alternatives:

  • allow such a refinement by default
  • have some sort of switch controlling the behavior (either standardized or provider-specific)

As there are pro's and con's of either approach, we'd very interested in user feedback on this.

Let us know what you think by posting a comment directly to this blog, shooting a message to the mailing list or participating in this Doodle vote. Which use cases you have encountered come to mind where the possibility to refine parameter constraints may help you?

25 comments:

Unknown said...

Jakarta HerbalObat Jantung Bengkakk

Peptide Synthesis said...

Thanks for providing such a great Information, you can see

shivani said...

A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training

htop said...

thanks for sharing this information
aws training center in chennai
aws training in chennai
aws training institute in chennai
best angularjs training in chennai
angular js training in sholinganallur
angularjs training in chennai
azure training in chennai
azure training in sholinganallur

محمد على said...


شركة تنظيف مكيفات بالرياض
شركة تنظيف كنب بالرياض
شركة تنظيف مجالس بالرياض
شركة تنظيف خزانات بالرياض

Unknown said...

Organic Chemistry tutor
hadoop training in chennai
Drilling consultants
Online drilling consultancy

Gaurav Sharma said...

Good blog informatve for readers such a nice content keep posting thanks for sharing
Best Hotel in Mussoorie
business news in hindi
CHOPTA – “Mini Switzerland of Uttrakhand"
TOP 20 HILL STATIONS OF INDIA

R ADK said...

Infertility specialist in chennaiSexologist in chennaiSexologist doctor in chennaiMale fertility doctor in chennai

عبدالله هادى said...


شركة تنظيف كنب بالرياض
شركة تنظيف مكيفات بالرياض
شركة تنظيف موكيت بالرياض
شركة تنظيف واجهات زجاج بالرياض
شركة تنظيف شقق بالرياض
شركة تنظيف فلل بالرياض

Bigg Boss 15 Episodes said...


Bigg Boss 15 Auditions. Want to be a part of Bigg Boss 15? Audition now only on
Voot Select! Fill in the below details to register for Bigg Boss 15 Auditions

Bigg Boss 15 Watch Online


======================================

[url=https://biggboss15episodes.com/]Bigg Boss 15 Watch Online[/url]

Jenny Aurellia said...

Bagi para penggemar yang ingin bermain Slot Online Deposit Pulsa Tanpa Potongan yang bisa dimainkan dengan sangat mudah dan dimanapun kapanpun kalian inginkan bisa langsung mengunjungi situs IDN89 yang sudah terpercaya melalui https://188.166.252.208/

Valluva said...

Thank you for sharing
Thanks For Your Blog

Satta King said...

I found this article extremely helpful. The article was very interesting to read. I appreciate your hard work for writing this awesome article. I do satta work, so please visit my website.
satta king
sattaking

Manage Transfers said...

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. Do you want to know about Manage Transfer and Final Expense Live Transfers?

digital guide said...

Our web developers make a-list designs for your websites, designed specifically to fit your industry, with your marketing message conveyed impeccably to your community and clients. Our work ethos and experience are shaped by their eye-catching and adaptable web designs. Click on best ppc agency in delhi ncr

Creationspot said...

Such a very useful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article. Do you want to know about some fancy bangles then click on our given product <a href="https://creationxpot.com/product-category/chokers/>online choker necklace</a>

Creationspot said...

Such a very useful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article. Do you want to know about some fancy bangles then click on our given product online choker necklace

KLF House said...

Such a very useful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article. We work to motivate people nlp therapy session in gurugram

Satta King said...

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. I found this article extremely helpful. The article was very interesting to read. I appreciate your hard work for writing this awesome article. I do satta work, so please visit my website.
satta king
sattaking

Manage Transfers said...

Such a very useful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article. Do you want to know about Manage Transfer and VA LIVE TRANSFERS?

periyannan said...

Nice blog post for reading and Thanks for sharing the wonderful article
internship request letter | Internship completion letter | internship companies | internship resume objective | internship application letter | Internship with training | internship email | internship experience | What internship means | Internship acknowledgement

DedicatedHosting4u said...

Thank you for putting up such a fascinating site. Please continue the discourse with some more pertinent subjects. We've come to read your blog because, as you know, there's no other reason for us to be here. Well, if you get time, you must checkout my website DedicatedHosting4u.com

nikita said...

Nice Post Your content is very inspiring and appriciating I really like it please visit my site for
gali satta
satta result
satta king
Satta Bajar
सट्टा किंग
delhi satta king
Disawar satta king
satta matka

kaashivit said...

Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve.
eniac full form in computer
dvd full form
sit full form
pcc full form
iucn full form
full form of lcd
brics full form
tally erp full form
full form of ctbt
crpf full form

sattaking said...

nice post and your content is very informative.I am very happy to see this post, i also share such kind of informations about the gali satta