标签: public-method

已发布和公共方法/属性之间有什么区别?

根据Martin Fowler的说法"有些东西可以公开,但这并不意味着你已经发布了它." 这是否意味着这样的事情:

public interface IRollsRoyceEngine
{
    void Start();
    void Stop();
    String GenerateEngineReport();
}

public class RollsRoyceEngine : IRollsRoyceEngine
{
    public bool EngineHasStarted { get; internal set; }

    public bool EngineIsServiceable { get; internal set; }

    #region Implementation of IRollsRoyceEngine

    public void Start()
    {
        if (EngineCanBeStarted())
            EngineHasStarted = true;
        else
            throw new InvalidOperationException("Engine can not be started at this time!");
    }

    public void Stop()
    {
        if (EngineCanBeStopped())
            EngineHasStarted = false;
        else
            throw new InvalidOperationException("Engine can not be started at this …
Run Code Online (Sandbox Code Playgroud)

design-patterns public-method

1
推荐指数
1
解决办法
382
查看次数

表格之间公共方法的访问

我试图在Form2的另一个窗体上访问Form1的公共方法,如下所示.我textbox6对form1 有一个控件,并且有绑定它的公共方法.但是我想用form2绑定它,如下所示.

Form1中

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 f2 = new Form2();
        f2.Show();
    }

    public void amount_sum()
    {
        string connstr = " server=.;initial catalog=maa;uid=mah;pwd=mah";
        SqlConnection con = new SqlConnection(connstr);
        con.Open();
        string sql = " select sum(amount)as amount from method";
        SqlDataAdapter dap = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            textBox6.Text = …
Run Code Online (Sandbox Code Playgroud)

.net c# winforms public-method

1
推荐指数
1
解决办法
2万
查看次数

公众或没有

在java中,为了使我们的变量或方法公开,我们真的必须这样做吗?例如:

void aaa() {
...
}
Run Code Online (Sandbox Code Playgroud)

要么

public void aaa() {
...
}
Run Code Online (Sandbox Code Playgroud)

如果是必须的,为什么?

java oop public-method

1
推荐指数
3
解决办法
2760
查看次数

PHP PDO:我们应该将pdo的`function __construct`设置为`private`还是`public`?

我们应该将pdo设置function __constructprivatepublic?如果我将它设置为易受攻击的主题public吗?

这是我的db类,

class pdo_connection
{
    public $connection; // handle of the db connexion


    public function __construct($dsn = 'mysql:host=localhost;dbname=xxx_2013',$username = 'root',$password = 'xxx')
    {   
    $this->dsn = $dsn;
        $this->username = $username;
        $this->password = $password;
        $this->connection();
    }


    private function connection()
    {
        try
        {
            $this->connection = new PDO($this->dsn, $this->username, $this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
            $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
        }
        catch (PDOException $e) 
        {
            # call the get_error function
            $this->get_error($e);
        }
        // return $this->connection;
    }
...
} …
Run Code Online (Sandbox Code Playgroud)

php pdo php-5.3 public-method

1
推荐指数
1
解决办法
1323
查看次数

盲目地调用公共方法(C#)

好的,奇怪的.我有许多带有转发器的用户控件,转发器的布局在所有控件中都是相同的,并且它们都有一个bindData()公共可用的方法.

我想知道,我可以设置另一个用于分页的usercontrol而不必指定父控件吗?

我能够做到以下几点:

((controls.specificuserControlClass)Parent).bindData();
Run Code Online (Sandbox Code Playgroud)

这一切都很好 - 但是specificuserControlClass如果你明白我的意思,我需要指定进入寻呼机然后需要"每个转发器"吗?

我可以Parent.bindData()盲目地从孩子控制中打电话吗?我"知道"该方法存在(或将构建检查以确保),但是Visual Studio并不满意,因为它不知道该方法.

c# asp.net public-method

0
推荐指数
1
解决办法
112
查看次数

私有构造函数由公共方法初始化

我遇到了私有构造函数的类,但是通过调用私有构造函数,该对象由另一个公共方法返回.当我们可以将构造函数公开时,这样的构造可能有什么优势?

public final class TokenTable {

    static public int errorToken = 0; 
    static public int timesToken = 1;
    static public int divToken = 2;
    static public int plusToken = 11;
    ......
    ......

    private final HashMap<String, Integer> keywordMap = new HashMap();
    private final HashMap<String, Integer> operationMap = new HashMap();

    private TokenTable() {

        operationMap.put("*", timesToken);
        operationMap.put("/", divToken);
        operationMap.put("+", plusToken);
        ....



    }


    static public TokenTable getInstance() {

            LexTokenTabInstance = new TokenTable();
            return LexTokenTabInstance;
    }

}
Run Code Online (Sandbox Code Playgroud)

java constructor public-method

0
推荐指数
1
解决办法
2542
查看次数

c#静态公共方法

在一个名为Security的类中,有一个方法:

    public static bool HasAccess(string UserId, string ModuleID)
Run Code Online (Sandbox Code Playgroud)

如何调用此方法,以便返回bool结果?

我尝试了跟进但没有成功:

    Security security = new Security();
    bool result = security.HasAccess("JKolk","Accounting");
Run Code Online (Sandbox Code Playgroud)

c# public-method

-2
推荐指数
1
解决办法
7147
查看次数

标签 统计

public-method ×7

c# ×3

java ×2

.net ×1

asp.net ×1

constructor ×1

design-patterns ×1

oop ×1

pdo ×1

php ×1

php-5.3 ×1

winforms ×1