Interface & Class
Hello guys! Interface & Class -> two important and basic pillars of object-oriented programming. Let's learn these concepts through a story! Note: I read this story in AI chat, but I converted it into my style for better understanding. In a village, a male chef in a house was trying to make a pizza at the demand of his sister. But he is not a professional; he learned all of these cooking stuff from his friends and by self-trying sometimes. So he didn't know how to cook a variety of dishes. He knew only some of the ingredients but not the entire process. He found a book in his house that was written by a famous professional chef. The book contained the making steps for pizza. But one thing: the book only tells him the steps, not the actual procedures for each step. They leave it in his hands, like: For pizza, make_crust() put_toppings() put_in_oven() These are the steps available in that book, so now he knows the steps to make a pizza, but the actual thing for each step lies in his hands. Then he started making pizza by following the steps. The chef implements the Pizza_Making_book with the steps said in that book. make_crust() -> he makes the crust with bread flour and with some yeast and sugar, like a plain bread. Note: this is not the only way to do make_crust() for pizza. For this reason, the manual only tells him the steps, not the actual ingredients, because it varies based on the chef's taste. After he makes the crust, he puts the toppings (put_toppings()) on it, like tomato, capsicum, onion, and some sweet things. Also, these toppings are not mentioned in that book, because they also depend upon the chef. Finally, he follows the manual and puts the pizza into the (put_in_oven()) microwave oven; hence, it can be baked well. He makes the pizza and serves it to his sister. From the above story, we can understand interfaces & classes. The Manual containing Pizza making steps is the Interface. The chef, who follows the manual, can be the class in programming. An Interface is a set of rules or a contract-like thing. It doesn't define the rules or give any definition to the rules, like the pizza manual. The actual responsibility for making the definition belongs to the class, like the chef. You may ask, why doesn't the interface define the rules? Because, it is like an index page of the actual code or logic behind that. The class is the logical member of the application. An Object is the Real entity that runs the application. So, making the rules in one place, like the interface, makes the code become more modular and more readable. It is also used to group the logical ideas that belong to the same flavor. Different pizza chefs follow the pizza manual. So, the pizza manual becomes the common one for all the chefs who make the pizza. I think you can understand this thing. Interface tells WHAT needs to be done! Classes tell HOW they are done! Objects are the ENTITIES that follow the entire structure and behave like a representative for the logical idea. That's it guys, hope you all understand these points. If you have any queries, put them in the comments. -End-

Hello guys!
Interface & Class -> two important and basic pillars of object-oriented programming.
Let's learn these concepts through a story!
Note: I read this story in AI chat, but I converted it into my style for better understanding.
In a village, a male chef in a house was trying to make a pizza at the demand of his sister.
But he is not a professional; he learned all of these cooking stuff from his friends and by self-trying sometimes. So he didn't know how to cook a variety of dishes.
He knew only some of the ingredients but not the entire process.
He found a book in his house that was written by a famous professional chef. The book contained the making steps for pizza.
But one thing: the book only tells him the steps, not the actual procedures for each step. They leave it in his hands, like:
For pizza,
- make_crust()
- put_toppings()
- put_in_oven()
These are the steps available in that book, so now he knows the steps to make a pizza, but the actual thing for each step lies in his hands. Then he started making pizza by following the steps.
The chef implements the Pizza_Making_book with the steps said in that book.
make_crust() -> he makes the crust with bread flour and with some yeast and sugar, like a plain bread.
Note: this is not the only way to do make_crust() for pizza. For this reason, the manual only tells him the steps, not the actual ingredients, because it varies based on the chef's taste.
After he makes the crust, he puts the toppings (put_toppings()) on it, like tomato, capsicum, onion, and some sweet things.
Also, these toppings are not mentioned in that book, because they also depend upon the chef.
Finally, he follows the manual and puts the pizza into the (put_in_oven()) microwave oven; hence, it can be baked well.
He makes the pizza and serves it to his sister.
From the above story, we can understand interfaces & classes.
The Manual containing Pizza making steps is the Interface.
The chef, who follows the manual, can be the class in programming.
An Interface is a set of rules or a contract-like thing.
It doesn't define the rules or give any definition to the rules, like the pizza manual. The actual responsibility for making the definition belongs to the class, like the chef.
You may ask, why doesn't the interface define the rules?
Because, it is like an index page of the actual code or logic behind that. The class is the logical member of the application.
An Object is the Real entity that runs the application.
So, making the rules in one place, like the interface, makes the code become more modular and more readable.
It is also used to group the logical ideas that belong to the same flavor.
Different pizza chefs follow the pizza manual. So, the pizza manual becomes the common one for all the chefs who make the pizza.
I think you can understand this thing.
Interface tells WHAT needs to be done!
Classes tell HOW they are done!
Objects are the ENTITIES that follow the entire structure and behave like a representative for the logical idea.
That's it guys, hope you all understand these points. If you have any queries, put them in the comments.
-End-