A
A
Akmat2017-08-21 11:27:01
Python
Akmat, 2017-08-21 11:27:01

Class and object attributes?

Link to the article
Share your personal experience in what situations are certain attributes used?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D3lphi, 2017-08-21
@D3lphi

If you're asking this question, then you don't have a deep (or any) understanding of Object Oriented Programming.
A class variable (or static properties) should be used only if in your task what it stores should be the same for all objects (Actually, the singleton (anti) pattern can be an example ). And yes, if you are interested, then class variables are used several orders of magnitude less often.
An object variable, as you might guess, when each object must be independent. And there are many more such cases.
In general, remember, static is global state, and global state is bad. So think very carefully before using it.

E
Egor, 2017-08-25
@egormmm

Make it a rule not to use a class attribute at all. This is not OOP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question