我该怎么做这个构造函数...... [英] How should I do this constructor...

查看:79
本文介绍了我该怎么做这个构造函数......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个用户登录系统。登录工作。

我想要做的是在类中创建一个可用于一般用途的变量数组。显然在大多数情况下在构造函数中设置数据。

我的登录/用户类中包含登录内容以及用户函数。在本课程中,我使用{ bool LoggedIn()}进行登录状态验证。所以这个类很好地构建,用户也没有登录。


所以我让构造函数进行登录验证?还是保留方法?或两者?使用构造函数中的方法(如果可能)登录验证然后设置详细信息?


不确定哪种方法最好,最有效。

So I have a user login system. The login works.
What I want to do is make a variable array in the class available for general usage. Obviously in most cases set the data in the constructor.

My login / user class has the login stuff within it, as well as the user functions. In this class I have {bool LoggedIn()} that I use for login status verification. So the class could very well be constructed and the user isn''t logged in.

So I make the constructor a login verification? Or keep the method? Or both? Use the method within the constructor ( if thats possible ) to login verify then set the details?

Not sure which is the best, and most efficient way.

推荐答案

你能详细说明你的问题,因为我不理解它(具体来说,我没有得到数组与Login类有什么关系)。
could you elaborate on your problem, because I didn’t understand it (specifically, I didn’t get what the array has to do with the Login class).


对不起宿舍...


我有一个班级用户。使用方法bool LoggedIn()。

该类具有登录功能,我将添加一个包含用户数据的数组变量。


我的问题是,我现在设置的方式是,LoggedIn()方法是判断用户确实登录的确定方式。

我只是好奇是否更容易重做构造函数来进行验证或在构造函数中使用LoggedIn()来设置用户数据,或者有两个单独的登录验证。我说两个,因为每个用户访问页面都会看到LoggedIn()是否允许访问。


真的我只是想知道哪种方式更有效。或者其他我没有看到的东西?
Sorry Dorm...

I have a class "Users". With a Method "bool LoggedIn()".
The class has the login functionality in it, and I was going to add to it an array variable with the user data.

My problem is, is the way I have it setup now, is that the method LoggedIn() is the determining way of telling wether or not the user is indeed logged in.

I''m just curious if it''ll be easier to rework the constructor to do the verification or use LoggedIn() in the constructor to set the user data, or have two seperate login verifications. I say two, because each user access page will see LoggedIn() to allow access or not.

Really I''m just wondering which is the more effective way. Or something else that I''m not seeing?


对于你的用户类来说,存储用户数据是明智的。传递这些数据的明显点是通过构造函数,虽然你也可以使用setter方法。


取决于loggedIn()当前的工作方式,我认为不需要改变方法。因此,您可以随意调用此方法。如果您需要关于课程代码的意见,请随时发布(或发送给我一个PM)。
for your user class it is sensible, to store the user data. the obvious point to pass this data is through the constructor, although you could also use setter methods.

depending on how loggedIn() currently works, I don’t see the need of changing the method. and as such you can call this method whereever you want. if you need an opinion about the class’ code, feel free to post it (or send me a PM).


这篇关于我该怎么做这个构造函数......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆