How do class methods work in iOS?

I used class methods and even wrote them along with books. I have heard of them described as factory methods. I understand that they work on the class itself, and not on the class instance. I also read about them, but I still don’t feel that I really understand them.

Can you suggest some good metaphors or key differences to help me and others understand class methods?

Part of my problem seems to be the dynamics between when you work on a class and an instance of the class. This remains a slippery issue that seems very relevant in this discussion.

Can anyone try to associate class methods with a real world metaphor?

I explained the resistance to my friends who do not have such a scientific science. This is not ideal, but it helps.

Imagine that water flows through a pipe unhindered. Now imagine that we have a rotary valve (just like the image attached). Let the valve close 80% of the path, which may cause less water to flow. The valve is “like” a resistor in an electric circuit, and water is “like” electricity, and the pipe is wire. To increase the resistance of the resistor, "like" the gradual closure of the valve in the flowing water pipe.

Is there a way to draw a metaphor between a factory car, a peanut butter sandwich, or something similar material?

Thanks for the help.

-A

alt text

+3
source share
1 answer

. () , - , . ( ) , . , , , - , (), . - ​​ , .

( : . Sodas - , . , , Objective-C.)

+5

Source: https://habr.com/ru/post/1785542/


All Articles