Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To property, or not to property?

Tags:

c#

wpf

dns

I am trying to figure out what would give me the nicest code. Which is a little subjective of course, I realize.

I have an application that accesses a database for which I have written an assembly that hides details about this database from all the applications that make use of this assembly.

I also have an WPF application that makes use of this assembly to display various cost calculations in which I would like to use databinding.

Databinding is only possible to properties of objects (as far as I got to work). This would mean I would need an object, preferably with INotify support and a range of objects. However, I would prefer to keep INotify and WPF things outside the assembly that handles database access.

How do others solve this: Keep WPF things outside the database layer (such as INotify) and inside your WPF allow binding? Write a wrapper? Or do most people put a 'property'/'INotify' class as data transfer object directly into the database layer?

like image 762
Jaapjan Avatar asked Jan 25 '10 16:01

Jaapjan


People also ask

What are the 3 types of property?

In economics and political economy, there are three broad forms of property: private property, public property, and collective property (also called cooperative property).

What is not real property?

Generally, “real property” is real estate. It includes the land and any permanent improvements to the land like buildings, fences, landscaping, driveways, sewers, or drains. “Personal property” is all property that is not real property like automobiles, livestock, money, and furniture.

What are the 5 types of property?

Real estate is considered real property that includes land and anything permanently attached to it or built on it, whether natural or man-made. There are five main categories of real estate which include residential, commercial, industrial, raw land, and special use.

What is property tax concessionary tax rate?

Owner-occupiers enjoy concessionary property tax rates ranging between 0 per cent and 16 per cent, while the property tax rates for those who rent out their flats range between 10 per cent and 20 .


3 Answers

Other people solve this by implementing the MVVM design pattern.

like image 123
Klaus Byskov Pedersen Avatar answered Oct 03 '22 01:10

Klaus Byskov Pedersen


You are laboring under a misconception. INotifyPropertyChanged is not a WPF thing. Consider:

  1. It is part of System.dll
  2. It is in the System.ComponentModel namespace
  3. It has been part of in NET Framework since version 2.0
  4. It is supported by most NET Framework data objects out of the box including ADO.NET's DataRowView and ComponentModel's ObservableCollection.
  5. It is automaticaly used by WinForms, ASP.NET, WPF, and many third-party packages for interfacing with data objects.

Since all the automatically-generated data layers Microsoft produces implement INotifyPropertyChanged, why should you treat your data layer any differently? Obviously your data layer needs to notify its clients somehow when properties change. Why not use NET Framework's built-in mechanism?

In my opinion any data layer containing mutable objects should implement property change notifications as a matter of course. INotifyPropertyChanged was designed to be such a notification mechanism, so why not use it as it was intended?

On a more general note: Adding an extra wrapper layer is generally just inefficient code bloat. Sometimes it is necessary and even beneficial, but don't do it just for the sake of doing it. Many times reasonably designed data layer objects work very well as view models. Only where your view model diverges from your data layer or where you need additional functionality should you consider introducing extra complexity, and then only on a case-by-case basis.

like image 20
Ray Burns Avatar answered Oct 03 '22 02:10

Ray Burns


I think the cleanest solution is to write a wrapper object in your WPF assembly and keep the INotify types out of the database assembly. There is no reason to add the complication of INotify to the database layer unless it provides a specific advantage.

like image 26
JaredPar Avatar answered Oct 03 '22 03:10

JaredPar