+ 1

What are the point of classes?

Just why?

13th Jun 2023, 9:53 PM
Podle Playz
Podle Playz - avatar
12 Respostas
0
That's the whole point of classes. That's also it's weakness, because it carries a lot of baggage, which might not be all neccessary...
13th Jun 2023, 10:39 PM
Bob_Li
Bob_Li - avatar
+ 4
sometimes a problem is easier to deal with if you clump data into a group and process it as a unit instead of dealing with them as separate values.
13th Jun 2023, 10:28 PM
Bob_Li
Bob_Li - avatar
+ 3
say you have a student. each have a name, age, grades, etc. you can have a list of student names, a dictionary of student name: student age, another dictionary of student name:student grade, etc. then you would have a lot of things to organize. If you have a class Student, then that student name, age, grade, etc is organized as a unit. It is easier to record and update.
13th Jun 2023, 10:35 PM
Bob_Li
Bob_Li - avatar
+ 2
When Alan Kay was first exploring the ideas that would lead to modern day OOP, he was inspired by cellular biology and how to apply that to large systems like servers. The concept of a 'class' can be traced back to thinking in terms of 'software'. A server is an object, the server's OS is an object, the OS's kernel is an object, the kernel's collection of networking protocols is an object, etc. The purpose of a 'class' in OOP (object oriented programming) is to define the *relationship* it has with the data it's given and the data it's expected to return. To reference the infamous gorilla, if there are seven of them in the jungle do you need seven gorilla classes to process their individual peelBanana calls? Or does your Jungle class need to hold a reference to seven gorilla data types and pass those to a single gorilla class when a gorilla needs to peel a banana?
13th Jun 2023, 11:17 PM
Sam
+ 2
classes serve as a fundamental building block for object-oriented programming (OOP). classes allow you to define a blueprint for creating objects that encapsulate data (attributes) and functionality (methods) together. Classes provide a way to structure and organize your code, promoting reusability, modularity, and maintainability. class Person: def __init__(self, name, age): self.name = name self.age = age def greet(self): print(f"Hello, my name is {self.name} and I'm {self.age} years old.") we define a Person class with two attributes: name and age.
14th Jun 2023, 10:51 AM
Vaibhav
Vaibhav - avatar
0
Elaborate please
13th Jun 2023, 10:29 PM
Podle Playz
Podle Playz - avatar
0
Oh ok that makes more sense, do variables and functions carry over classes?
13th Jun 2023, 10:36 PM
Podle Playz
Podle Playz - avatar
0
So just doing a simple "#<------------>" is more effective
13th Jun 2023, 10:40 PM
Podle Playz
Podle Playz - avatar
0
it depends. As long as your classes are compact and simple, they keep the data coherent and easier to process. The problem starts when you start complicating stuff and link classes by inheritance. Then your code starts to feel like a house of cards.
13th Jun 2023, 10:49 PM
Bob_Li
Bob_Li - avatar
0
Ok
14th Jun 2023, 6:37 AM
Podle Playz
Podle Playz - avatar
0
Ok
14th Jun 2023, 11:06 AM
Raj Ratan Gupta
Raj Ratan Gupta - avatar
0
Oh ok
14th Jun 2023, 2:27 PM
Podle Playz
Podle Playz - avatar