繼承是一種“is-a”關係;總結“界面”關係的好方法是什麼?——總結其他關係? (inheritance is an 'is-a' relationship; What is a good way to summarize the 'interface' relationship? -- Summarizing other relationships?)


問題描述

繼承是一種“is-a”關係;總結“界面”關係的好方法是什麼?——總結其他關係? (inheritance is an 'is-a' relationship; What is a good way to summarize the 'interface' relationship? -- Summarizing other relationships?)

Title:  inheritance is an 'is-a' relationship;  What is a good way to summarize the 'interface' relationship?

Also, I think it would be nice to have a repository of simple relationships to help people put things in perspective.  I'm fairly new to programming so I'm not sure if there's really enough 'relationships' to warrant this aspiration-- but if there is, this may be a good place to start.

  • inheritance = "is-a"
  • composition = "has-a"
  • interface implementation = ?... 

參考解法

方法 1:

Interface implementation = "can-do"

An interface usually represents one ability that you can implement in a class, for example in .NET the IEnumerable interface is used for classes that you can enumerate, and IComparable for classes that you can compare.

方法 2:

why not just "implements a"? guess I'm not sure what you're driving at.

方法 3:

Your predicates is-a and has-a describe the structural relation between different types. In that sense, an interface should also get the is-a. 

However, there are more possible taxonomies and also more oop key concepts:

  • An interface is a contract that each implementor fulfils (promises-to).
  • Connection between objects can be established not only using composition but also by passing objects to methods (uses-a) or involving kind of messaging (notifies-of).
  • The purpose of inheritance is not only polymorphy (as-a) by differently implementing the base class methods but also to add new functionality (properties, methods) - (extends-a).
  • The role of objects in an OOP application may be classified with manages-a, creates-a, visits-a, substitutes-a, etc.
  • ...

方法 4:

Maybe "as-a" or "like-a": Implying that it has some properties/abilities but isn't directly derived from.

方法 5:

Interface is a "fits-into" relationship.

Think about the electrical socket in your wall.  That is your interface to the electrical grid.  You may have many objects that share such an interface (i.e. they all "fit-into" the socket).

Other countries have different interfaces, along with differenct sets of objects which will "fit-into" those particular schemes.

(by Evan SevyGuffajcomeau_ictxKaken BokJon EgertonJimmy)

參考文件

  1. inheritance is an 'is-a' relationship; What is a good way to summarize the 'interface' relationship? -- Summarizing other relationships? (CC BY-SA 3.0/4.0)

#repository #interface #Relationship






相關問題

開發代碼時如何使用 Internet Subversion 存儲庫? (How to use an Internet Subversion respository when developing code?)

在線庫報告的錯誤 (Online repository for reported bugs)

如何在Subversion儲存庫歷史記錄中查找文件? (How Do I Find a File in a Subversion Repository History?)

如何從 Nexus Professional 遷移到 Nexus OSS (How to migrate from Nexus Professional to Nexus OSS)

如何查看存儲庫? (How to see repositories?)

將遠程 github 存儲庫中的更改合併到本地存儲庫 (Merge changes from remote github repository to your local repository)

如何為 Xcode 項目設置 Git 存儲庫? (How to set up a Git repository for an Xcode project?)

如何簽入從不同存儲庫簽出的代碼 (How to check in code which is checked out from different repository)

如何使 Hg/Git 成為遠程倉庫? (How to make Hg/Git a remote repo?)

繼承是一種“is-a”關係;總結“界面”關係的好方法是什麼?——總結其他關係? (inheritance is an 'is-a' relationship; What is a good way to summarize the 'interface' relationship? -- Summarizing other relationships?)

存儲庫模式問題 (Repository Pattern Question)

為 Mac 和 Windows 設置 React Native 代碼庫 (setting up react native code repository for Mac & Windows)







留言討論