Designing a better API?

后端 未结 10 774
无人及你
无人及你 2021-02-04 18:07
  1. What are the best practices and patterns to be followed for designing APIs?
  2. How to achieve implementation hiding the best way (C++/Java)?
  3. Designing APIs
10条回答
  •  渐次进展
    2021-02-04 18:43

    You can implement the following guidelines:

    1) use established or known methods, examples:

    createPatientRecord();
    createPatientAppointment();
    createPatientCheckup();
    

    2) returning values:

    • throw an exception if any
    • if no object found, return null
    • if several objects, return empty list not null

    3) consistent arguments ordering/sequence

    recallPatientRecord(long patientId, long hospitalId);
    recallPatientRecord(long patientId);
    recallPatientRecord(long patientId, long hospitalId, int disciplineCode);
    

提交回复
热议问题