1

I have a project , I used Coefirst . In my project I Want Implement SoftDelete there is two way .

1st: User an Interface Like belowe :

 public interface ISoftDelete
{
    bool IsDeleted { get; set; }
}

If I use this way , I should Implement all classes that I want softDelete.

2nd : use An Abstract Class Like belowe :

public abstract class SoftDelete
{
    public bool IsDelelted { get; set; }
}

I dont know which one is better and there is no similar question on the Net.

Kar Inter
  • 303
  • 2
  • 3
  • 12
  • Possible duplicate of [Interface or abstract class?](http://stackoverflow.com/questions/1165332/interface-or-abstract-class) – Maksim Simkin Dec 03 '16 at 08:33

3 Answers3

1
  1. Keeps it nice and simple, you don't need any special handling for the IsDeleted objects.

  2. You will need to handle inheritance in your database, that means realistically table per type inheritance. I'd recommend against this for this kind of approach as it will complicate queries and migrations, and can lead (down the line) to performance issues.

So I'd say 1 is better, even though it requires duplication in the code, its probably going to save you some headaches in the db.

gmn
  • 4,199
  • 4
  • 24
  • 46
0

Interface is a data passing contract and you don't have any implementations but abstract class can have default implementations. If you want to have implementation in your base class (here SoftDelete) you must use abstract class.

0

according to MSDN

If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.

I think Interface is better choice

Recommendations for Abstract Classes vs. Interfaces

ihsan
  • 59
  • 9