K
K
KirylLapouski2018-02-22 09:49:09
OOP
KirylLapouski, 2018-02-22 09:49:09

Why are abstract properties needed?

Why are abstract properties needed? Is it necessary to define a class as abstract if it declares an abstract property?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2018-02-25
@KirylLapouski

You initially formulated the question incorrectly - therefore its essence is not clear. What are class properties? The properties of a class are the characteristics that describe it. For example, let's take a regular stack class, what properties does it have?
1. It stores a lot of objects in itself
2. It has information about the number of stored objects, which is usually implemented using an attribute (field) of the class
3. It has the ability to receive an object according to the "First in - last out" principle, which is usually implemented using the method
Judging by the comments, you are asking about class attributes (fields) - components that describe the stored data. Abstract attributes have the same purpose as abstract methods, i.e. their tasks:
- declare the presence of attributes that must necessarily be present in child classes
- "rearrange" implementation details to child classes. It should not be forgotten that class attributes, like methods, can also have different implementations - their data can be stored in memory or calculated on the fly (and some programming languages ​​provide for such implementations accordingly)

A
Andrew, 2018-02-22
@andre_k

With abstract methods, you can define 'points' for future extensions of your application.

A
Ainur Valiev, 2018-02-22
@vaajnur

abstract classes, like interfaces, have no inherent functionality, but are useful in organizing code. This is good code formatting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question