2019-03-21 09:57:27 +01:00
|
|
|
<!doctype html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
2019-05-22 16:03:19 +02:00
|
|
|
<link rel="stylesheet" href="./3rdparty/highlight/styles/default.css">
|
2019-03-21 09:57:27 +01:00
|
|
|
<link rel="stylesheet" href="../css/doctest.css">
|
2019-05-22 16:03:19 +02:00
|
|
|
<script src="./3rdparty/highlight/highlight.pack.js"></script>
|
|
|
|
<script src="../dist/iwmlib.js"></script>
|
2019-03-21 09:57:27 +01:00
|
|
|
</head>
|
|
|
|
<body onload="Doctest.run()" >
|
|
|
|
<h1>
|
|
|
|
Interfaces
|
|
|
|
</h1>
|
|
|
|
<p>
|
|
|
|
Interfaces are objects that specify (document) the external behavior of objects
|
|
|
|
that “provide” them. An interface specifies behavior through method definitions
|
|
|
|
that specify functions and their signatures.
|
|
|
|
</p>
|
|
|
|
<p>Let's look at an example of an interface and a class implementing the interface:</p>
|
|
|
|
<script class="doctest">
|
|
|
|
|
|
|
|
class ITestable extends Interface {
|
|
|
|
reset() {}
|
|
|
|
run() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Testable {
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
print("Resetting testable object")
|
|
|
|
}
|
|
|
|
|
|
|
|
run() {
|
|
|
|
print("Running testable object")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<p>We can now check whether the promised interface methods are implemented by the
|
|
|
|
class:</p>
|
|
|
|
<script class="doctest">
|
|
|
|
Doctest.expect(ITestable.implementedBy(Testable), true)
|
|
|
|
</script>
|
|
|
|
<p>
|
|
|
|
<h2>
|
|
|
|
References
|
|
|
|
</h2>
|
|
|
|
<ul>
|
|
|
|
<li><a href="https://zopeinterface.readthedocs.io">Zope Interfaces</a></li>
|
|
|
|
</ul>
|
|
|
|
</body>
|