3

I recently ordered a new credit card. I used the price comparison websites to find the best one that met my requirements.

I notice that these websites have a lot of validation on the client side. For example please see here: https://www.moneysupermarket.com/credit-cards/search/?goal=CC_ALLCARDS&purpose=AllCards&from=SSComponent. If you enter an invalid date of birth (under 18 years old), then there is client side validation that immediately says: "Unfortunately we can only provide product information to users aged between 18 and 99 years of age.". I would expect this logic to be in the domain layer rather than the presentation layer.

The reason I ask is because I read an article recently that said the website in question are champions of DDD? Is there a pattern/approach I am missing here. Is the presentation layer calling the domain layer through AJAX?

w0051977
  • 7,031
  • 6
  • 59
  • 87
  • No necessarily. They probably are validating on the client-side and probably they have implemented the same validation on both server and client side. What they do should be easy for you to check. Checkout the browser console. Pay attention to the XHR calls before and after the age validation. – Laiv Aug 08 '17 at 19:28
  • Please see [this answer](https://softwareengineering.stackexchange.com/questions/351419/clean-architecture-validation-in-domain-vs-data-persistence-layer/351662#351662). – John Wu Aug 08 '17 at 19:30
  • The only I miss in your answer is that validations on client-side reduce the server load too :-) – Laiv Aug 08 '17 at 19:33
  • @Laiv, in reality, that doesn't happen as not re-validating on the server side risks problems if someone bypasses the front end and attempts to inject data to your backend directly. – David Arno Aug 09 '17 at 08:59
  • @DavidArno I got It. – Laiv Aug 09 '17 at 09:03
  • There's nothing wrong with client side validation in DDD. If client-side improves usability and usability is a key success factor... where's the problem? – ZioBrando Aug 10 '17 at 08:39

1 Answers1

1

Not all code that executes in the client is presentation layer. Increasingly with the advent of JavaScript frameworks like Angular and React, it's more common that logic is implemented client-side. The client-side applications have their own layers just like the server-side applications do. In the example you've linked to they have validation logic in the client's domain layer regardless of whether it's duplicated validation logic in the client or the client delegates to server for validation.

Samuel
  • 9,137
  • 1
  • 25
  • 42
  • Not sure how I have managed to downvote this. Could you edit your answer and let me know so that I can change my downvote to an upvote? – w0051977 Aug 10 '17 at 09:04