CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2011
    Posts
    4

    Questions About Using Classes.

    Hello.

    I am a newbie and currently writing a couple of WPF applications to improve my work productivity. I had a specific question regarding using classes in the windows based applications.

    Let's say my application will 1) get personal data entry from user and 2) save them to the DB.

    What is the correct way of doing it?

    A. Get user entries from WPF windows called "Person.xaml and Person.xaml.CS" then, saves the entries to a object of class called Person from "Person.CS", and finally save them to the DB.

    B. Get user entries from WPF windows called "Person.xaml and Person.xaml.CS", use the variables declared in Person.Xaml.CS, then save to the DB? Since I have created an object of WPF Windows when the application loaded, isn't it also an OOP?

    Thank you in advance. Your answer will help me in improving my coding skills greatly!

    ADDED:

    I guess I kind of understand what OOP is... but then, I am not sure how to implement it while coding.
    For example, one of my application of tracking grocery products... I will need 3 classes for Vendor, Product, and Customer.

    Do I create class files for each of the objects AND separate WPF windows for each of the objects?
    or Can I just use the WPF windows as a class file?

    I hope you understand what my confusions are >.<
    Last edited by prideofjc; May 6th, 2011 at 04:08 PM.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Questions About Using Classes.

    Generally you want to keep the WPF UI part (the 'View') separate from the database operations (the 'Model') with an intermediate object (the 'ViewModel').

    In other words the UI should be dumb and bind to an intermediate object that contains properties and operations. When the UI performs some action, it contacts the viewmodel object, the vm object, contacts the model object and the data is saved to the database (via the model).

    For more info on the Model View-ViewModel pattern, search Bing for "WPF model view-viewmodel tutorial".

    There are several good articles listed.

    P.S. At first this pattern is going to seem like some extra work (and it is), but there are many benefits to coding this way. One such benefit you can easily swap out different UIs. Also, it is easier to unit and/or integration test.

  3. #3
    Join Date
    Feb 2011
    Posts
    4

    Re: Questions About Using Classes.

    Thanks for enlightening me! I knew something was missing!

    I heard about MVVM many many times but never took time to read/reserach about it!

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