Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
An Interface is a contract that guarantee specific functionality is defined for an object. By using interfaces, one developer can write the implementation details, while another developer can be assured of how they will interact with that object. We'll look at what this means and how interfaces fit with class hierarchy.
Course: Dependency Management with Composer
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
Learn more about the PHP Framework Interop Group (PHP FIG)
A group of established PHP projects whose goal is to talk about commonalities between our projects and find ways we can work better together.
-
0:00
[MUSIC]
-
0:04
If you have a drivers license, you've probably driven more than one car.
-
0:09
You don't have to relearn to drive every time you drive a new car,
-
0:13
because each car uses the same interface.
-
0:16
There's the way to accelerate break, turn and shift gears.
-
0:20
Each car may handle a little differently, and
-
0:22
you'll feel more comfortable with certain vehicles, and it's the same way with code.
-
0:27
If you're familiar with one logging system and switch to another logging system with
-
0:31
the same interface, the transition should be fairly easy.
-
0:36
Although you may feel more comfortable working with the system that you find most
-
0:41
familiar.
-
0:42
Hi, I'm Alina and in this course, we're going to look at an important concept,
-
0:47
an object-oriented design called interfaces.
-
0:50
An interface is a type of contract
-
0:53
that assures certain abilities are available on a particular object class.
-
0:58
Interfaces have continued to gain popularity in PHP.
-
1:02
As the use of package management through composer has become the standard.
-
1:07
By having standard interfaces, package maintainers can more easily build and
-
1:13
maintain packages for common tasks, such as logging, caching, and HTTP messages.
-
1:19
The PHP Framework Interop Group, or PHP FIG for short,
-
1:23
has also been a leader in standardizing common interfaces.
-
1:27
Check out the notes associated with this video to learn more about composer,
-
1:32
standards, and the fig.
-
1:34
So how do interfaces fit with class hierarchy?
-
1:37
Lets talk tomatoes.
-
1:39
Botanically speaking, a fruit is a seed baring structure
-
1:43
that develops from the ovary of a flowering plant.
-
1:46
Where as vegetables are all other plant parts such as, roots, leaves, and stems.
-
1:53
By those standards, tomatoes are a fruit.
-
1:56
In culinary terms, however, it's a different matter.
-
2:00
When cooking, many foods,
-
2:02
such as tomatoes, which botanically speaking are fruits,
-
2:06
are typically considered vegetables because they are savory rather than sweet.
-
2:12
If a tomato were a PHP class, it would inherit it's properties from the fruit
-
2:18
class, but it implements the savoryFlavor interface of a vegetable.
-
2:23
Allowing us to use these fruits in recipes that require a savory flavor.
-
2:29
In this course, we'll explore interfaces and
-
2:32
abstract classes by building a website that displays different types of content.
-
2:40
Using pages and blog posts, we'll explore the use of interfaces through
-
2:45
the creation of these different types of content.
-
2:48
We'll also pull that content from different data sources.
-
2:53
The project will combine interface contracts with class hierarchy by creating
-
2:58
an abstract class and demonstrate how abstract classes can be used
-
3:03
to enforce the contract of an interface while building a class hierarchy.
-
3:09
This course will explain the differences between interfaces and
-
3:12
abstract classes, and give you the knowledge you need to build, and
-
3:16
implement both in your own projects.
You need to sign up for Treehouse in order to download course files.
Sign up