I
I
Igorek982021-06-15 11:31:14
OOP
Igorek98, 2021-06-15 11:31:14

What is the best way to name an instance of a class?

There is class Folders {}
And it would be more convenient for me to call the instance like Foldersthat, and the class itself folders, but all the articles insist on the opposite.
How to call an instance of a class conveniently and beautifully, so that it is noticeable in the code and everything is Feng Shui?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stefan, 2021-06-15
@MEDIOFF

Capitalize classes, variables, and instances (which you also store in variables) - with a small letter, and everything will be fine, PEP8 will help you

D
Damir Shaniyazov, 2021-06-15
@shaniyazovdamir

Using the Java example class Folders {} - the class is a template by which an instance of the new Folders() class is created - using the new operator, an instance of the Folders class is created folders - the folders variable of the Folders type. The variable type allows you to determine which methods can be called on an instance of the class. For example, in Java, all classes inherit (extend) from the Object class, so we can write Object folders = new Folders(); and the methods of the Object class will be available to us. Folders folders = new Folders(); - this line reads like this: "The folders variable of the Folders type stores a reference to an instance of the Folders class.
Folders folders = new Folders();



Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question