+ 1
What are the point of classes?
Just why?
12 Respuestas
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...
+ 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.
+ 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.
+ 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?
+ 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.
0
Elaborate please
0
Oh ok that makes more sense, do variables and functions carry over classes?
0
So just doing a simple "#<------------>" is more effective
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.
0
Ok
0
Ok
0
Oh ok