Keeping validation logic in sync between server and client sides [closed] - database

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In my previous question, most commenters agreed that having validation logic both at client & server sides is a good thing.
However there is a problem - you need to keep your validation rules in sync between database and client code.
So the question is, how can we deal with it?
One approach is to use ORM techniques, modern ORM tools can produce code that can take care of data validation prior sending it to the server.
I'm interested in hearing your opinions.
Do you have some kind of standard process to deal with this problem? Or maybe you think that this is not a problem at all?
EDIT
Guys, first of all thank you for your answers.
Tomorrow I will sum up you answers and update question's text like in this case.

As mentioned in one of the answers to the other post, if you are going to keep your layers separated, there is no good way to avoid duplicating the validation logic in each layer. If you use something to automatically tie them together, you have introduced a sort of coupling between the layers that might hinder you down the road. This might be one of those cases where you just have to keep track of things manually.
However you go about it, you have to make sure each layer is doing its own validation, because you never know how that layer is going to be accessed. There's no guarantee that all the layers you implemented will always stay together.

I like to use a validation service, which doesn't necessarily care about the origin of the data to be validated. This can work in a few different ways when you get to the part about transmitting validation rules to a client (i.e. web page), but I feel the most important aspect of this is to have a single authority for the actual validation rules.
For example, if you have validation logic on your data core entities, like a collection of ValidationRule objects that are checked via a Validate method - a very typical scenario, then I would promote those same rules to the client (javascript) via a transformation.
In the ASP.NET world (the only one I can speak to) there are a couple of ways to do this. My preferred method involves creating custom validators that tie in to your UI widgets to fields (and all their validation rules) on your entities. The advantage of this is that all your validation logic can be bundled into a single validator. The down side is that your validation messages will become dense, since the validation rules are all tested at once. This can, of course, be mitigated by having your validation logic return only a mention of the first failure, etc.
This answer probably sounds sort of nebulous and unspecific, but the two points that I'd like to make are:
Validation should occur as close as possible to the points where data is entered and where it's committed.
The same validation rules should be used wherever validation occurs - if client-side validation passes, then it should never fail validation later on (pre-save business rules, foreign key violation, etc.)

Some framework provides a validation support the may keep your client and server validation in sync. Take a look at this Seam validation tutorial using annotations. It's a good implementation and very easy to understand.
Anyway, if you don't wan't to rely on frameworks, I think it is easy to implement something similar.

If you're using ASP.Net there are a number of validation controls you can use. These controls are written in a very generic way, such that most of them automatically duplicate your validation logic between the client and server, even though you only set options for the control in one place.
You are also free to inherit from them to create additional domain specific validators, and there are third-party control packs on the web you can get that add to the base controls.
Even if you're not using ASP.Net it's worth taking a look at how this is done. It will give you ideas for how to do something similar in your own platform.

Related

MVVM advantage for freelancer developer? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a freelance developer. Is there any real advantage to use the MVVM pattern?
I know that the MVVM is most used for large teams, because of the great division between design and code.
But what about a freelancer like me? I should use the MVVM pattern anyway, instead of patterns like MVP and MVC?
Personally, I think that MVVM goes hand in hand with WPF. When I started learning WPF, it was a nightmare... it's just so different to Winforms for instance. But when I found out about MVVM and started using it with WPF, everything just fell into place.
It makes perfect sense to have a class (view model) that holds all of the data that you need for a particular Window or UserControl (view). That used to be one of my biggest problems... where do I put this bit of data?
Another problem that I had was creating and fully understanding DependencyProperty objects and the variety of handlers that they come with. With MVVM, we don't need to worry about these... we can just use normal CLR properties, albeit with a call to the INotifyPropertyChanged' interface. No longer do I need to worry about setting up astaticPropertyChangedCallback handler just to monitor incoming values.
The only difficulty that I found with MVVM was the bit about 'not using the code behind'... but once I discovered that this is more of a request than a rule, then the problem mostly went away. Once I then found out that Attached Properties can implement most of the UI event-type functionality that one would normally put into the code behind (such as MouseDown events, etc.), then not using the code behind became a whole lot easier too.
For me, this is a simple choice... unless the project is going to be small, I'd always pick MVVM to use with WPF.
I think that this depends more on what framework you use and what the client wants. Also I think there are very few cases when you start a project from scratch, most of the time you will work on already existing projects and then is a good idea to follow whatever is already started.
But, if you have no outside constrains and start from scratch, I think that whatever feels most comfortable for you is the best. For me, MVC is good enough for most of the projects.
The MVVM pattern was originally designed for WPF but can be applied to other frameworks to greater or lesser degree. I would advise using the MVVM if using WPF, it makes for cleaner more manageable code and there is little overhead in following this pattern. Not too complicated and definitely not just for large projects, small projects often grow into larger projects and following a mature pattern such as MVVM from the outset rather than retro-fitting at a later date is good practice.

Planning a database app [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am in the planning stages of a database app for personal use. I have a good bit of the database structure planned, but as I think about how I'm going to write the program, it made me wonder if I'm doing this in the right order.
Which should I be planning first, the db structure or the classes?
I think designing your data model first is a very good idea.
If the app is to be database driven it is a good idea to have an solid understanding of what your data model is going to look like before even attempting to write any code.
You can still conceptualize how you think the classes may look as your thinking about your data model. Keeping this in the back of your mind as you determine your requirements will help when you begin to write some code as well.
Of course, as you begin to write code you will probably have to revisit your data structure, so it is an iterative process, but good planning at the onset of the project is a good idea.
I think you will get a differnt answer from data centric poeple vice application centric people. Personally I always start with the data but an application programmer would probably start with the classes.
In reality, I think you need to work on the two at the same time.
They most often develop together, although it's often easiest to start designing the basic structure of the database, and then move to the code. You'll find that depending on the size of your application the database will change frequently along the way to final product.
I typically plan as best I can, then I start creating the database per the planning/design specs I wrote for myself.
Then, I use something like Linq-To-SQL to generate some basic DAL classes -- wrap those in a repository class that manages most of my CRUD situations.
Depending on the complexity of the app, I then write a GUI which consumes the repository directly (quick/dirty) or I write a domain logic class (and potentially Data-Transfer-Objects or dumb POCOs) which wraps up the functionality in the repository.
Obviously, the best planning misses things, so make sure you take in to account that you'll have to go back and add fields, change types, add relationships etc.
If the purpose of your system is to store, retrieve and report on data, then I would say by all means it is appropriate to design the database first.
If, on the other hand, the purpose of the system is to implement a business process or processes using software, then it will often be more efficient to design the "domain model" first, modeling out the business process into objects/classes, then determining how to persist them to/from a database later.

Ways to get past the Inner-platform effect while still building highly customized web apps?

Feel free to answer the question in the title as generally as I posed it, I offer some more details and specifics below.
Currently I develop and maintain a somewhat legacy business app (ASP/SQL) that is highly customizable allowing for moderate to full customization on: custom fields, forms, views, reports, actions, events, workflows, etc. This customization is necessary in the domain we develop for and has allowed us to build a niche.
I have been reading up on the inner-platform effect and ways of implementing high level user defined customization and have concluded that we do suffer from many of the inner-platform effect problems because essentially we have created a high level abstraction on top of the SQL. The organization of custom fields is implemented in a similar way to the approach found here
http://blog.springsource.com/arjen/archives/2008/01/24/storing-custom-fields-in-the-database/
We use something similar to the meta database method described in that article. All customization is built around this approach and in many ways we suffer from database on top of a database.
The end result is something that looks fantastic on paper yet the more features are added and custom coding is done for clients the more of a mess everything becomes. It seems that the more I read the more I realize this is somewhat of an anti-pattern. It also seems that the more I try to read the more I find so little has been written on the topic. Anyways, I am trying to learn modern approaches to this problem and trying to find more discussion/articles on the topic. Are Database systems such as CouchDB relevant to this type of application?
My question is clearly pretty general. It seems like there is a lot against this kind of application in favor of just "knowing and defining your domain better". Are there any good/better ways to implement this kind of application? I'm not looking for black and white answers, and any further readings on the subject would be fantastic. Thanks for any help.
My answer is be conscious and clear about what is for a plugin to do and what is a user setting. In that case, your platform and your settings are different. Your application provides basic services and is unabashedly a platform. It may also provide an application built on that platform.
So in that case you focus on programmer interfaces instead of implementation possibilities.
The standard advice in CS is to create another level of abstraction, not sure if that's not the problem here.
The only advice I could give is to push as much functionality onto the database, given it's the platform. SQL Server supports custom functions, fields and stored (SQL) procedures.
Either that or try to pull repeated functionality into separate functions in ASP.

UI Advice: how to design a form with a lot of data [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm re-writing an app that is a data-entry tool. The existing app is in Access and consists of a form with multiple grids, with each grid containing many columns that requires the user to scroll horizontally in order to view columns.
The current grids on the form are layed-out heirarchically in parent-child relationships. Top grid represents projects, grid below that represents the SKUs in the selected project, the grid below that represents season data (pricing, shipping info, etc) for the selected SKU above.
I'm looking for advice regarding good UI design principles for this kind of app. How do I design a form that gives the user the flexibility to see all columns for the data on the form without needing to scroll so much?
What are some good online resources for UI principles for business apps?
Thanks!
What I've found to be a general rule of thumb that helps to develop aesthetically pleasing user interfaces is the notion of only presenting as much as is needed for any given task.
One of the approaches we can take in designing forms is to focus the user's attention to the task or function at hand by centering controls on a horizontal axis.
Culture, too, plays a major role in the acceptance of the programs we write. For instance, in Western culture, we read from left to right and from top to bottom. Therefore, programs targetted for a Western audience should ideally follow that same design principle.
Here's some basic principles that will help
use friendly words and terms over obnoxious and demanding tones:
"The file could not be found at the location 'c:\temp'" as opposed to "A required file could not be found please fix the error."
single color schemes that apply to the overall look and fonts
common control layout on all forms presents
follow the design guidelines generally employed for the platform you are targetting
References
Here is some reference material to help you on your own unique path
(Windows) User Experience Interaction Guidelines
(Apple) User experience guidelines
Windows design principles
(Windows) Some design pointers
To summarize, I've found that overwhelming the user with all the information he/she might ever need to perform a simple data entry is not really an ideal way; rather progressively presenting functionality and the tools to do what they want is, to me, a much better alternative.
As always, place youself in the user's position: "Do I like what I see? Does it make me happy to work with it? Is the program too restricted? How can I make task X much easier to perform?"
usability.gov is a great resource for UI design. Also, check out wufoo.com, which is a form hosting website. Their blog is chock-full of interesting research on usability and form design.
This site may help you out: http://www.jankoatwarpspeed.com/post/2009/02/18/How-to-deal-with-large-webforms.aspx. Big points there being tabs & collapsible regions.
Additionally, if you don't necesarily need to show all of those columns horizontally, you can present them when the user clicks the entry to view more details. I typically prefer to show the critical information, and then require the user to view more details if they need specifics.
As Mike mentioned, "the notion of only presenting as much as is needed for any given task"

WPF or workflow?

I have a question and hopefully you can steer me in the right direction.
I'm working on an application that needs some form of decision tree/work flow for lack of a better term. I'll describe it below for some clarity.
I have a request form that users will fill out on a web page. At the beginning of the form is a 'Referral Type'. Bases on the referral type selected some of the form questions will change. There could be 2, 3 or 4 groups of questions depending on the Referral type. Entire groups of questions can be pass or fail.
If the first group of questions fail..then the form stops processing, etc.
What would be the best approach to handle this? Would WPF work well in this situation?
WPF is the Windows Presentation Foundation and is more about the User Interface than a work flow management system. For work flow, you could build your own home-grown database driven solution, or you could use tools like Ultimus or Sharepoint.
You may also be thinking of the Windows Work Flow Foundation.
I have used both Ultimus and home-grown implementations for work flow management. Peers have used Sharepoint. There are benefits or pros/cons to each.
I am unsure how well Workflow works with ASP.NET as I've never tried it. I believe some of the samples may actually cover this so it's possible. That is the first technical hurdle.
It sounds like the logic isn't too complicated. There are a finite number of "paths" that a user can take based on the referral type. Each path is fairly linear, with 2-4 "groups" of questions. Can each group sit on a single page? That would simplify things greatly.
A web framework such as Spring.NET Web Framework might be better suited for this task than Workflow. You are trying to express some condition logic--essentially, "go to the next page if X, else end questioniare". Spring.NET handles this exact sort of logic with its Validation Framework and the Results Mapping.
Workflow is certainly well-suited for this kind of logic, but is there anything that happens in reasponse to each group of questions other than validation? If not, it may be overkill.

Resources