What aspect of programming are classes and constructors useful? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

What aspect of programming are classes and constructors useful?

8th Jul 2019, 3:04 PM
eMBee
eMBee - avatar
6 Answers
+ 10
When you want to write a code, that's similar to you want to write a scenario. In your scenario there are many people with different manner, characters and special relations. These people are your classes. Constructor define how these people are born. They define the initial state of your classes. Indeed without classes and object oriented aspect of programming, it's a difficult work to write large codes.
8th Jul 2019, 3:18 PM
Qasem
+ 8
Constructors are just a part of the classes, so I'm just quietly going to ignore you said that. Classes are useful when you are trying to make lots of objects of the same type. So if, let's say, you want to make a ball. You will need its positions, radius, velocities, and methods to move it. You can make an object if you only want one ball. But if you want to, let's say, make 30000 balls. Hopefully you are not going to write 30000 of the same object. You just make a class. Classes are a little better than constructor functions (imo), since they don't need to access the prototype to actually add methods to it
8th Jul 2019, 3:09 PM
Airree
Airree - avatar
+ 5
Airree, I said constructors so that one won't relate what I mean by classes to classes in school not like I don't know constructors are part of classes
8th Jul 2019, 3:12 PM
eMBee
eMBee - avatar
+ 5
Constructors are just parts in a class. Classes are helpful in object oriented programming. A class is like a blueprint for an object. One class can be used to create several objects. Without classes programming would be tiresome due to large codes.
12th Jul 2019, 7:56 AM
Eugiene Kanillar
Eugiene Kanillar - avatar
+ 4
if you can visualize entanglement then classes and Constructors unify as one to become a process in the end that called a module. Classes serve as a type of memory organization blueprint or subroutines called to create objects. Of course as you well know Constructors created within the classes have the job of initializing the objects Relevant data and establishing an invariant of the class in conclusion, the main aspect in programming is its ability to create program code templates for creating objects with values and behaviors that can be called through the module.
9th Jul 2019, 9:26 PM
raymond wescott
raymond wescott - avatar
+ 2
Classes are the containers that holds data members like variables, fields, properties and member functions like Methods, Constructors, delegates. It helps to bind all these functions together so to have a protection from outside world. Constructors are special methods and are basically used to initialize the variables. Constructors reside within classes only and its name should be equal to the name of the class. Constructors are called when we create an object. If you don't assign a constructor on your own, compiler will assign an implicit constructor that will be responsible to assign the values to the variables declared.
14th Jul 2019, 12:14 PM
Rohan Rao
Rohan Rao - avatar