开发者

What appropriate way to create and use class ? (example inside)

Now. I so confuse when use any classes. What is best practice approach to use them?

Example I have a UserClass name User that have 2 attributes UserName and Password

when I use I will create new object like this

UserClass userObject = new UserClass();

this is my question that I so confuse to use

If i want to call Method name "Login" what is appropriate way to us开发者_开发知识库e them?

Between 1 Set Value to Attribute of Object Like this

      userObject.UserName = "user";
      userObject.Password = "password";

      if (userObject.Login())
      {
           //Do Something After Login
      }
      else
      {
           //Show Something when Error
      }

   2 Send Value as parameter
      if (userObject.Login("user","password"))
      {
           //Do Something After Login
      }
      else
      {
           //Show Something when Error
      }

From above What is appropriate approach to use and apply to any classes?

Thank you very much for your guidance _/\_

P.S I practice to be better Programmer


Use a property to store information that belongs to the object. (eg, a Username)

Use a parameter to pass information to a single method which doesn't have to do with the rest of the object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜