What is all this 🙄 omg I am not understanding anything ... :/ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is all this 🙄 omg I am not understanding anything ... :/

What is class and what is object and what can I do with them ,, why do i need them ,, in what ???

23rd Dec 2016, 2:09 AM
Majd
2 Answers
+ 6
Classes and objects are a more natural way to structure larger programs. It's a very important paradigm in programming! Classes are a blueprint for a data structure called an object. In a class, you list the sorts of data/variables that its objects will hold (fields), and create methods that determine what the object can do (behaviors). For example (I use this example too much lol), you could create a PlayingCard class, with fields for a card suit and a card value. It would have behaviors to give the card a suit/value, or retrieve it's suit/value. Then, you could make a Deck class. It would have a field for an array of 52 PlayingCard objects. It would have behaviors to initialize the deck, shuffle it, and draw a card. This Deck could then be used for a Game class...you see where this is going? Everything related to a PlayingCard or a Deck is all wrapped up in 1 object. Or here's another example: An online store has Shoppers/Customers, who have Carts, which contain Products. They all have their own related data and behaviors.
23rd Dec 2016, 4:49 AM
Tamra
Tamra - avatar
+ 6
...I am VERY SORRY for that wall of text lol ^_^;
23rd Dec 2016, 4:50 AM
Tamra
Tamra - avatar