Class diagram - dependency or association from class to interface?

喜夏-厌秋 提交于 2019-12-20 03:10:42

问题


I have a question regarding creating a class diagram where I have used dependency injection.

I have following code example:

public class ReservationController : ApiController
{
    private readonly IGetReservationService _getReservationService;

    public ReservationController(IGetReservationService getReservationService)
    {
        _getReservationService = getReservationService;
    }

    // GET list of all reservations
    public List<ReservationViewModel> GetReservations()
    {
        return _getReservationService.GetReservations();
    } 

    // GET single reservation by id
    public List<ReservationViewModel> GetReservation(string reservationNumber)
    {
        return _getReservationService.GetReservation(reservationNumber);
    }

}

Here you see that the controller (ReservationController) getting the IGetReservationService injected in the constructor. When creating the relationship between the controller and the interface, do you then use a dependency or an association?

My guess is that it should be a dependency since we are using dependency injection?

Good day.


回答1:


Yes, this is a dependency. An association is used if you have object references (e.g. for a property).



来源:https://stackoverflow.com/questions/37157727/class-diagram-dependency-or-association-from-class-to-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!