Expressive Interface¶
An expressive interface, refers to an API design pattern that makes code more readable, intuitive, and natural to write. It emphasizes clarity and ease of use, often resembling natural language.
The goal is to make your code self-documenting and reduce the cognitive load on developers reading or writing it.
An expressive interface is not related to an interface: it may be implemented without them.
The notion of expressive interface is similar to the fluent interface.
<?php
class script {
function hello() {
print 'Hello ';
return $this;
}
function word() {
print 'word.';
return $this;
}
}
$script = new Script();
$script->hello()->world();
//
?>
See also Fluent Interface.
Related : Fluent Interface, Self-documenting, Interface
Related packages : bassim/super-expressive-php