c#


Interface vs abstract class when dealing with only properties [closed]


This is not a technical roadblock or a challenge, I would say it's a general discussion!! If this is an inappropriate forum, please let me know I will delete it..
I have scenario where in get 10 xml from a webservice, each XML few common properties and few specific properties to that XML.
Class structure would look something similar to below
Public abstract class employee
{
Public int Id {get; set;}
Public int Name {get; set;}
}
Public class PermanentEmployee: Employee
{
// PermanentEmployee specific props
}
Public class ContractEmployee
{
//Contractor​ specific properties
}
Given the above scenario, should employee class be abstract or it should be interface. Which is better.
I will have Only properties, No methods.
My take : I would go for abstract class as I can reuse properties, Interface won't make sense as there are no methods..
I you want to "reuse" properties into several "child classes", I would always use an abstract class.
In case you want to just define the method signature and NOT the "logic body" of it, then use interface.
In conclusion, the source code you share with us, it would be the way I would do.
I would define an interface IEmployee and also the abstract class. That gives the flexibility of an interface to pass around generically, but the abstract class will be useful for those cases where you would otherwise have to repeat code (DRY etc).
public interface IEmployee
{
int Id { get; set;}
int Name { get; set;}
}
public abstract class Employee : IEmployee
{
public int Id { get; set;}
public int Name { get; set;}
}
public class PermanentEmployee: Employee
{
// PermanentEmployee specific props
}
public class ContractEmployee : Employee
{
//Contractor​ specific properties
}

Related Links

what are alternatives of Threadpool ? [closed]
On-demand compile-time code generation in C#
0x3 error using pdbstr (Source indexing)
Delete a line form a text file
WPF - put the name of every textblock in an array
Is there a .Equals function in C# that takes into account nulls?
Cancel all async tasks
I can't use a “kill” process in my code. (its underlined with red) [closed]
Excel crashes when editing column
Advantages of using cmd.exe /c over not using cmd at all
400 Bad request when sending XML to WCF
Visual Studio 2015 SSIS - Custom SSIS component not picked up in SSIS toolbox
How can I rewrite values from an array into a second array with each 2 letters being flipped? (C#)
Load multiple assemblies
Display random pictures in picturebox each 0,5sec
Load the layout async in Xamarin

Categories

HOME
c#
max
microcontroller
dronekit
android-ndk
reference
highmaps
crm
flowtype
doctrine2
genexus
obd-ii
dcos
guidewire
appsettings
greensock
reportlab
openam
google-street-view
aws-devicefarm
spring-webflow
summernote
datazen-server
coccinelle
fastboot
screen-scraping
concatenation
ithit-webdav-server
jira-zephyr
visual-studio-community
proof-general
launchd
checkmarx
restangular
delphi-2010
ocl
openvms
javafxports
campaign-monitor
oracle-bpm-suite
aspose.pdf
quartz
synchronized
remap
dynatable
zedgraph
bipartite
suitesparse
group
stripes
android-music-player
visual-web-developer
hdr
altova
rowname
syslog4j
normalisation
django-taggit
stdlist
periodic-processing
containstable
gtkwave
maven-antrun-plugin
recode
om
eaaccessory
sparkcore
transparentproxy
data-representation
autopep8
fedena
fxmlloader
mind-manager
windows-search
javacompiler
livescript
traceur
email-headers
nvcc
ie-developer-tools
pechkin
extensibility
mandelbrot
jython-2.5
stringstream
proj4
generator-expression
moonscript
feincms
jquery-1.8
sup
commonsware
automapper-2
zend-validate
file-processing
text-manipulation
miniport
webdb
hp-trim
rpxnow
ffdshow
file-icons

Resources

Encrypt Message