Here is a question. I dont think there is a right or wrong way Im just curious to see your opinion.
The code is in C#.
I have 2 classes.
public class Author
{
public int AuthorID{ get; set; }
public string AuthorName{ get; set; }
}
public class Book
{
public int BookID{ get; set; }
public int AuthorID{ get; set; }
public string BookName{ get; set; }
}
I want to create a static method that gets a List of books by an AuthorID
Like this:
public static List<Book> GetBooks(int AuthorID)
{
List<Book> lstBooks = new List<Book>();
lstBooks = //(code to get all this authors books from DB goes here)
return lstBooks;
}
Here is the question:
Would you put this static function in the Author class or in the Book class or somewhere else?
Unless I've misinterpreted, the OP is asking about the C# code. So your suggestion of having the Book class inheriting the Database class:
class Book : Database {
...
}
Would mean that code like this would be valid:
Book book = getBookFromSomwhere(...);
Database db = book; // valid code, but what does this mean ?!?!?!?!?
And accordingly, Book objects would have to have database-themed methods (https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.database?view=entity-framework-6.2.0) like BeginTransaction and ExecuteSqlCommand. All of this makes absolutely no sense (to me at least, and I suspect any reasonably experienced software engineers), which is why I object to the idea of Book inheriting a DB class.