I'm pretty new to programming with Object Oriented Programming Languages. So please how do you explain the concept of object oriented programming to a kid?
相关问题
- how to define constructor for Python's new Nam
- Keeping track of variable instances
- Object.create() bug?
- std::vector of objects / pointers / smart pointers
- Name for a method that has only side effects
相关文章
- 接口B继承接口A,但是又不添加新的方法。这样有什么意义吗?
- NameError: name 'self' is not defined, eve
- Implementation Strategies for Object Orientation
- Check if the Type of an Object is inherited from a
- When to use Interfaces in PHP
- Are default parameters bad practice in OOP?
- How to return new instance of subclass while initi
- In OOP, what is the best practice in regards to us
Object Oriented Programming (OOP) is the art of code to some, and a really hostile programming environment to others. OOP is basically when you use constructors/classes to define objects. OOP is beneficial in my profession, because of its developed design patterns such as inheritance and encapsulation. Although OOP does have a few flaws, it's really useful when you want to use one of the 24 design patterns, but can be annoying when dealing with simple functionality. I would recommend it when you would like to create multiple objects with the same methods and values. You should google it for furthermore info & how you can learn it. I recommend author Marijn Haverbeke's book called Eloquent Javascript. The free PDF of the whole book is here. This book helps you master JavaScript and talks a lot about OOP starting from the 6th chapter called "The Life of Objects". I hope this helped you learn more about OOP :)
Some of the key concepts you need to understand are objects and classes for Object Oriented Programming (OOP). This is a very basic explanation, but hope can help you understand other documentation.
Let's compare OOP with chocolate molds. The first thing you have to do to make some chocolates, you need to build its mold. The mold will have some characteristics for the future chocolates like shape, size, etc. depending on how you create the mold the future chocolates will be.
Once the mold is ready you can create the chocolates. All chocolates will take the mold characteristics, will have the same shape and size, but there will be some characteristics on the resultant chocolates that you will be able to modify like i.e. the type of chocolate (black or white), you will also be able to fill in the chocolate with different things like nuts, almonds, peanuts, etc.
So, in this analogy, the mold are classes and they will condition the resultant chocolates. Chocolates are objects created based on a class. Objects are also called instances of a class.
Classes have attributes or variables, on this analogy the attributes would be: chocolate_type: (black/white), chocolate_filler (nuts, almonds, peanuts, nothing, etc), elaboration_date, due_date.
When a new object is created you will have to define each one of their attributes like: chocolate1: black, filled with nuts, elaborated: 01/01/2016, dd: 03/01/2016 chocolate2: white, filled with almonds, elaborated: 01/01/2016, dd: 03/01/2016 chocolate3: black&white, filled with nuts, elaborated: 01/01/2016, dd: 03/01/2016
Chocolates Analogy
The attributes of a class are defined using variables such as string, boolean, integer, etc.
Also each object can have methods/functions that will define their behavior (what actions each object can perform).
https://en.wikipedia.org/wiki/Object-oriented_programming
Hope, this very basic explanation helped you.