vendredi 5 août 2022

Is passing object property against Dependency Inversion Principle? Please advise

Assuming there are classes as follow.

interface Book {
  Guid Id { get; }
  Guid AuthorId { get; }
}

interface Author {
  Guid Id { get; }
  void Autograph();
}

Then there are service and data store

interface AutographService {
  void Sign(Guid bookId);
}

interface BookStore {
  Book GetBookById(Guid bookId);
}

Given that the entry point is to call AutographService.Sign(bookId), there are BookStore and AuthorStore injected into AutographService. Does the following data store violate Dependency Inversion Principle?

interface AuthorStore {
  Author GetAuthorById(Guid authorId);
}

And how about the following instead?

interface AuthorStore {
  Author GetAuthorByBookId(Guid bookId);
}

Aucun commentaire:

Enregistrer un commentaire