The standard class...is it mutable or not?
相关问题
- how to define constructor for Python's new Nam
- Keeping track of variable instances
- Object.create() bug?
- std::vector of objects / pointers / smart pointers
- Name for a method that has only side effects
相关文章
- 接口B继承接口A,但是又不添加新的方法。这样有什么意义吗?
- NameError: name 'self' is not defined, eve
- Implementation Strategies for Object Orientation
- Check if the Type of an Object is inherited from a
- When to use Interfaces in PHP
- Are default parameters bad practice in OOP?
- How to return new instance of subclass while initi
- In OOP, what is the best practice in regards to us
It depends strongly on the language. Some of them do not even allow mutable objects.
Many mainstream languages default to being highly mutable, depending on what members you expose on your class's public interface. In at least a couple mainstream languages (particularly dynamic languages) it is really hard to make immutable objects.
See a definition of (im)mutable for more information:
A mutable class is a class that has a changeable state. for example, if you have a class representing a number,
Number
, then it is mutable if you can do something likei.e., change the internal state.
from Wikipedia:
Classes are typically not mutable (though some languages deviate from this). The objects that you create from classes, on the other hand, are often mutable if they include state and you do not take special care to prevent anyone from changing that state after object creation.
A mutable class is one that can change its internal state after it is created.
Generally speaking, a class is mutable unless special effort is made to make it immutable.
"Usually" (as in usual languages) it is mutable.