Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1003477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:59:11+00:00 2026-05-16T07:59:11+00:00

Imagine a hypothetical object with a number of attributes: pseudocode: class Student { Name:

  • 0

Imagine a hypothetical object with a number of attributes:

pseudocode:

class Student
{
   Name: String;
   Birthdate: DateTime;
   Height: int; //inches
   GPA: float; //"Grade Point Average"
   Citizenship: string;
}

Now the user enters in values, and the object gets them:

Name: Shelby Lake
Birthdate: 6/19/1991
Height: 63
GPA: 5.6
Citizenship: United States

And the layer with all the business logical can validate it:

BusinessLayer.ValidateStudent(student);

In this example it could, for example, throw an exception:

ClientException
GPA cannot exceed 4.00 (5.60)

Okay, fine. But not everything the user types in can “fit” inside the object:

Name: Shelby Lake
Birthdate: 19 years ago
Height: 5'3
GPA: n/a
Citizenship: n/a

The fact that our users are allowed to enter in more friendly values in a business decision. At the same time there are global business rules that decide when some input is valid, e.g.

GPA: 5.6 (invalid)
GPA: n/a (valid)
Citizenship: n/a (valid)
Citizenship: (invalid)
Height: tall (invalid)
Height: 5'3 (valid)

My problem is, where do i store these string values, since i cannot store them purely in the object. They need to get to the business layer, which knows how to parse entered text into values.

My first thought is to change the class:

class Student
{
   Name: String;
   Birthdate: DateTime;
   BirthdateFreeForm: string;
   Height: int; //inches
   HeightFreeform: string;
   GPA: float; //"Grade Point Average"
   GPAFreeform: string;
   Citizenship: string;
}

This allows the more arbitrary values to be sent to the business layer:

Name: Shelby Lake
BirthdateFreeform: 19 years ago
HeightFreeform: 5'3
GPA: 4.6
Citizenship: n/a

BusinessLayer.ValidateStudent(student);

And the business layer can convert free-form values into canonical values, reporting any errors:

ClientException
Country of citizenship must be entered ("n/a")

But that seems like such an ugly answer i don’t even want to consider it.

What’s the enterprisey way to parse user input with business rules?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:59:12+00:00Added an answer on May 16, 2026 at 7:59 am

    One approach I’ve taken when data entered by the user differs significantly from the way the model represents data is to use a specific class for a view model, and provide helper methods within this class to translate that view model to a proper domain object:

     class StudentViewModel {
        StudentViewModel(Student s) {
           // map the properties of Student to the appropriate view model 
           // properties.
        }
    
        StudentViewModel() {
           // use this for creating a new student.
        }
    
        Name: string
        Height: string
        GPA: string
        // etc.
    
        Student GetUpdatedStudent() {
            // map your view model properties to the Student class 
            // and return an updated Student.
        }
     }
    

    This approach is extremely flexible, although there is some additional work involved. You can validate directly against the ViewModel rather than the domain object, and be guaranteed that your models do not need to accomodate against invalid data, which allows them to focus on their true purpose of representing your domain, rather than constantly guarding against invalid data.

    In addition, this approach becomes incredibly useful when you have a “flat” user experience that translates into a deep object graph.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this hypothetical example, imagine I have an object FooSet that has five properties
Imagine I have one common functionality: series and number (string and integer) of some
Imagine you want to animate some object on a WinForm. You setup a timer
Imagine an object you are working with has a collection of other objects associated
Imagine I have String in C#: I Don’t see ya.. I want to remove
Consider the following hypothetical people management system. Suppose each Person object belong to a
Imagine that I have a general class Person . Then I have specializations of
Imagine two tables: Shifts, RANK_S_DAY. Shifts contains a ShiftDate column which is DateTime and
Imagine that I have a generic base class like this: public abstract class AnimalDTO<TA,
Imagine you homebrew a custom gui framework that doesn't use windows handles (compact framework,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.