[Tutor] OOP, classes ,

ThreeBlindQuarks threesomequarks at proton.me
Mon Oct 3 14:24:11 EDT 2022


Mert, could it be the hard way is not the best way for you to start? Your book may not be at the best level for you at this time.

Having people here explain in detail here may be overkill. It would help if you asked something more specific.

I will try and answer partially from a Python perspective. Object Oriented Programming is not done the same way in different languages or sometimes at all.

I think I view a class as a sort of recipe. You have a recipe for a cake that may list some ingredients and methods. You do not yet have a specific soup or cake, just a recipe and that is called a class. You can make an object using a recipe and now you have a cake or whatever. You can make many objects of the same kind, but that are also different in that the recipe may say to use a cup of any kind of jam, or optionally do some extra preparation at the end like adding icing on a cake.

Once you have a recipe, you might want to make something similar enough so that instead of redoing the entire recipe, you simply say that the recipe inherits from another recipe EXCEPT for some changes such as additions or somewhat different methods. You can, for example, have a recipe for making bread that requires flour and yeast and so on, and another recipe for making French Toast that incorporates making the bread first and slicing it then adds eggs and so on. The recipe for French Toast can Inherit from the recipe for Bread and you can talk about Bread being the parent and French Toast being the child. 

You can play with analogies all you want and come up with oher concepts but the idea in general is that a class in Python contains a combination 
of things in it that range from storage of something to functions that can manipulate the contents and so on. It can get much more complex but in some ways is a bit like a recipe. Classes do not in some ways normally exist unless used as a prototype to make objects. I mean, yes, they exist, but mainly as an idea. Objects are instantiations of the idea with some fine-tuning. If a class is declared as having one (or more) other classes as parents, then any object you create from such a class inherits attributes from not only what the class declares, but what various parents and grandparents have declared. It is a hierarchy of a kind but you also can make a sort of tree of ancestors but probably rarely need to.

There are rules galore but in general, some things inherited can be changed and tailored. All the above is part of the evolution of programming languages so you can package related data and procedures together but also a different paradigm in how you think about solving problems in an object-oriented way.

So starting with a somewhat easier book and then learning the hard one may be best. Or get one-on-one tutoring from a live human near you.

You need to explain where "Comparison" comes into your question. Are we talking about comparing classes or objects or asking if an object has a particular parent or about telling the system how to compare an object with another instance and declare which order they are in, or something entirely different?

- 3



Sent with Proton Mail secure email.

------- Original Message -------
On Monday, October 3rd, 2022 at 6:30 AM, Mert Oner via Tutor <tutor at python.org> wrote:


> Hello tutors,
> I am studying python with the help of a book called ' Learn Python3 The Hard Way' by Zed Shaw. I am having a really hard time understanding OOP and classes, grandparent, parent and child concepts in classes and Inheritance vs Comparison.
> Could you please help me out in layman terms? Or maybe some easy to understand study metarials.
> I really appreciate you guys, taking precious time from your daily life to help us beginners.
> Peace!
> Mert Sage
> 
> Sent from Yahoo Mail on Android
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list