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?

  • 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 8 '17 at 19:28
  • Please see this answer. – John Wu Aug 8 '17 at 19:30
  • The only I miss in your answer is that validations on client-side reduce the server load too :-) – Laiv Aug 8 '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 9 '17 at 8:59
  • @DavidArno I got It. – Laiv Aug 9 '17 at 9:03
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.

  • 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 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.