After several days of this, you begin to notice that there are lots of other people doing this too, and it is taking a lot of time to get your yellow fruit drink, so you decide to help the person make yellow fruit drink faster and better. When you look at each step of making yellow fruit drink, you notice several things that could be better.You see that some people are bringing three fruits or one fruit or some of them are bringing both yellow and red fruits and the person is having to figure out what to do with each person's fruit. So you go in front of him and make sure that everyone in line has exactly two fruit and only yellow fruit. This makes everything faster for the person, because they're working with the same number and kind of fruit every time.
You also see that the person is adding different things each time to make the yellow fruit drink sweet, so you get one big bag of sweet stuff so the person can just use the same stuff each time.
You also see they have different size glasses and have to make different sizes of yellow fruit drink each time, so you get a large number of the same size glasses so the person can make the same size yellow fruit drink each time.
You then see that the person is doing too much work for just one person, so you go get other people to help make yellow fruit drink. The first person takes the yellow fruit from the people in line and hands it to the other people to make into yellow fruit drink, and then the first person gives the finished drink back to the people in line. This makes the line go faster, but people do not like this as much: they saw a person and expected that person to make their yellow fruit drink. They don't like other things too: they want something different to make their yellow fruit drink sweet, or they want a different size glass. Since this only happens because the people in the line can see the person behind the table, you decide to build a box around the table so that people in line cannot see the people making the yellow fruit drink or the glasses or the sweet stuff. This works, and the people in line go back to being completely happy.
So now you have a big box next to the road with a sign that reads "Yellow Fruit Drink Maker" on it. As people walk up to it, they see two holes in the front of the box and a thing to push in the middle: the hole on the left has a sign that reads "Step 1: Add two yellow fruits"; the thing to push has a sign that says "Step 2: Press this"; the hole on the right has a sign that says "Step 3: Take yellow fruit drink".
Now things are much easier! The person inside the box can change anything they want to, as long as they take in two yellow fruits and give back a yellow fruit drink. They could change the sweet stuff to something that needs less money, or they could change the other people who are helping make the yellow fruit drinks to other people or even to machines, and nobody outside the box minds because they are still getting their yellow fruit drink.This is what we call Encapsulation.
We find some way to point out only what our work will accept coming in and what our work will always give back, and we hide the rest. We could do any kind of work we want to inside the box, but as long as everyone in line can count on us to keep taking the same things in and giving the same thing back, they don't care how we do it inside! This lets us make sure that the work we are doing inside is the easiest, or the fastest, or uses the least stuff, or whatever is most important to us inside the box, without anything outside the box trying to tell us what to do.
No comments:
Post a Comment