CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 53

Threaded View

  1. #14
    Join Date
    Nov 2008
    Location
    United States
    Posts
    81

    Re: Object Validation

    I'm going to try to make a class using that example. I think its a little more clear. I think I was getting confused when I was told that an object needed to validate itself. I thought that it ment that the objects validation functions needed to be inside the object itself. After reading the last post I'm thinking that it meant the object needed to call the validation functions automatically, and not rely on the user to call the validation function before calling the save function.

    So I can leave the object by itself?

    Code:
    public class Person
    {
        private string m_firstName;
        private string m_lastName;
    
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
    Code:
    public class PersonProvider
    {
        public void Save(Person p)
        {
            // Save
        }
    }
    Code:
    public class Form1
    {
        
        Button1_Click
        {
            Person p = new Person();
            p.FirstName = "Bob";
            p.LastName = "LOL";
            PersonProvider pProvider = new PersonProvider();
            pProvider.Save(p);
        }
    }
    I know this doesn't have to do with validation but it helps me in the same way to understand how to organize the class.

    Should Save() (and other functions) be put inside Person or should they be put inside PersonProvider? I have seen both examples where the Person class is ONLY the Person object, and the functions that maniuplate ther Person class are within another class called PersonProvider. I've also seen the maniuplation functions like Save(), Load(), CalculateSalesTax(), etc.. inside the Person class.

    It makes more OO sense to me, to have them seperated, but by doing that I mess up my data security because I have to make all of the fields inside Person public so that PersonProvider can access them. Unless I derived PersonProvider from Person.. But I'm not sure that makes sense.

    I'll post back my final code for the validation when I get it finished.
    Last edited by Three5Eight; December 9th, 2008 at 12:14 PM.
    Three5Eight
    Using: MS C# 08 EE, MS SQL 05 EE, C++ .Net 08 EE, Vista Home Premium, XP Home

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured