Should one interface inherit another interface

后端 未结 6 1902
抹茶落季
抹茶落季 2021-01-30 12:17

I can\'t seem to find an answer on this and just want to make sure it\'s an ok coding standard. I have interface A that is used by many different classes and don\'

6条回答
  •  感情败类
    2021-01-30 13:10

    I think databases always provide a great way to demonstrate interfaces, so considering if an interface should inherit another interface look at the following,

    IMySqlDatabase : IDatabase
    MySqlDatabase : IMySqlDatabase
    
    IMsSqlDatabase : IDatabase
    MsSqlDatabase : IMsSqlDatabase
    

    A MySqlDatabase IS an IMySqlDatabase and an IMySqlDatabase IS an IDatabase.

    Now if you need to make changes to your IDatabase interface it's grandchildren (the conrete database classes) can reap the benefits, but you won't have to expand MySQL AND MsSQL (or perhaps even more DBMS' Interfaces). At the same time in your middle man (IMsSqlDatabase) you can still have interface features that a MySQL or Oracle DB wouldn't support.

提交回复
热议问题