Do I correctly understand what a class is?

前端 未结 9 924
Happy的楠姐
Happy的楠姐 2021-01-01 20:52

I\'ve had trouble finding a clear, concise laymans definition of a class. Usually, they give general ideas without specifically spelling it out, and I\'m wondering if I\'m u

9条回答
  •  长发绾君心
    2021-01-01 21:45

    A class is basically a way to organize your code.

    It allows you to put all of the code related to one abstraction (think "concept" or "idea") in one place.

    As an example - in your example of an app, the Window with the two buttons, a text box, and some code for handling what happens when the user types in the information may be organized into a single class: something like "PromptWindow". This class would be made up of multiple classes internally (two buttons, a textbox, etc) This would probably be used by some separate class, which would create an instance of the PromptWindow class, call a method on the class to show the window, then use the results.

提交回复
热议问题