Pankaj Bhatia
Pankaj Bhatia

Reputation: 202

Make Subset Class if needed only Few Properties from Class

I have a class which has 100+ properties. I am using WPF/MVVM where i have to show all records of that class, but in my listing screen i need only 10 properties. To show so what should i do now make object of same class having 100+ fields or make a new with only 10 properties in it?

Upvotes: 0

Views: 124

Answers (1)

mm8
mm8

Reputation: 169200

It you want to show 10 out of those 100 properties just like they are, there is little reason to define a new type.

Of course those other 90 properties will be initialized with their default values for each instance of the class that you create so if you are intending to create a lot of instances, have a constrained memory limit or if the existing class does some fairly heavy initialization stuff, you should probably consider creating another type and use this one.

But in general it is perfectly fine to bind to a subset of the total number of public properties of a class without creating a new sub-type.

Upvotes: 1

Related Questions