What's Object Oriented Programming? [closed]

2020-06-30 04:09发布

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?

标签: oop
3条回答
仙女界的扛把子
2楼-- · 2020-06-30 04:25

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 :)

查看更多
够拽才男人
3楼-- · 2020-06-30 04:27
  • A design patern to develop an application in a more moduler way, rather than writing a flat coded application & preventing repetition of code. For example, if i have a bug in the code - i can go and fix the bug in one place, knowing i won't have to edit the same code in different places.
  • Easlaly organize my code - separetly, to handle different issues in my application. For example, comunicating with the database - so i'll have specific (class) files that handle my DB.
  • Customizing my own objects using classes can help define methods, properties and events, that will apply on all created objects later. For example, if i have a website that singns up users - i can automatically create a new user object that has all the funtionalities that all the other users have.
  • OOP can help create different settings for different objects without repeating code by creating some kind of a template. Sooo.. in continue to the previous users example, i can set a general user class that has common general settings, and apply it to all users, extend it with other classes such as admin users, regular users, baned users, ect' - without repeating my code.
查看更多
来,给爷笑一个
4楼-- · 2020-06-30 04:29

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.

查看更多
登录 后发表回答