DAO classes with CRUD VS methods. DAO classes with entity methods

I was wondering what is the right way to create a DAO pattern between the two options, which I explain below.

Scenario

I have a movie theater web application, with Filmand type objects Showing. This is a PHP application, but I think this question applies to any OO programming language ...

Option A: CRUD only

Create another class DAOInterfacethat defines the CRUD methods insert, get, updateand delete, and implement this interface in such classes as FilmDAOand ShowingDAO.
Thus, I will use the same method getto extract “all films for today” or “all films of a certain genre”, so I need to set some array of arguments to decide which objects to get ...

Option B: Essential Methods

Create a variety of interfaces, such as FilmDAOIntand ShowingDAOInt, define the methods that are specific to each individual object, such as getFilmsByDate, getFilmsByGenre, getShowingsWithDiscount, etc.

Question

Is it just a matter of taste, or is any of these approaches better than the other? And why?

+4
2

, , , ( ), . :

  • - , CRUD. , SQL group by, .

  • CRUD , (, , ), , .

  • CRUD . , , . - .

  • CRUD . , .

  • DAO, , , CRUD DAO, , (, ). .

, , , - ORM, CRUD, . , DAO; , , CRUD, . , , , , Rails , ActiveRecord.

+1

, i.e.

:

// generic Dao interface applies to any Dao
interface IGenericDao[T] {
   findById(Long Id): T
   findAll(): List[T]
   countAll(): Integer
   delete(Id: Long)
   create(element: T)
   modify(Id: Long, modification: T)
}

// offers everything from IGenericDao plus Film-specific
interface IFilm extends IGenericDao[Film] {
   findByName(filmName: String): List[Film]
}

// offers everything from IGenericDao plus Showing-specific
interface IShowing extends IGenericDao[Showing] {
   findByDayAndTime(when: Timestamp): List[Showing]
}

class GenericDao[T] implements IGenericDao[T] { ... }
class FilmDao extends GenericDao[Film] implements IFilm { ... }
class ShowingDao extends GenericDao[Showing] implements IShowing { ... }
+1

Source: https://habr.com/ru/post/1542763/


All Articles