Answer the question
In order to leave comments, you need to log in
How to set properties to several objects of different classes through 1 method?
I have several objects that need to set the display language when getting it from the database. How to implement that 1 object set the language for all the necessary objects at once yyy)
once
Answer the question
In order to leave comments, you need to log in
Let the objects that require the language follow the language themselves (implement as a trait).
Here it is fundamentally important to first decide on two things:
1) Are all instances of classes that need to be informed about a language change known, or are there many of them and they are created from various places?
2) How often the language changes, how difficult it is to “recognize” it, and how those classes work with the language.
Accordingly, as options that can solve the problem:
1) Traits (as a variant of multiple inheritance), in my opinion, is not obvious and difficult, not portable.
2) Inheritance from the Localized class, if it can be logically built into the inheritance chain and the language setting code for each descendant class is similar.
3) Interfaces if inheritance is not possible OR the language setting code/logic is different for different classes.
4) Callback functions, each class that needs information about changing the language can register a Callback in the language manager in the constructor, and delete it in the destructor.
5) Update the static variable in the language manager class and just use it in the classes that need the language.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question