使这个C#程序函数成为一个OOP函数 - 摆脱参数 [英] making this C# procedural function an OOP function - get rid of theparameters

查看:51
本文介绍了使这个C#程序函数成为一个OOP函数 - 摆脱参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨同事们,


我不知道这是不是正确的团队,但它是在C#中所以我试试。

我有一个名为GetInfo的#3程序函数..这些是3

重载方法。我想使用OOP方法来重构

这个。


功能正常但我希望采用OOP方法

有人可以帮我重构吗??????

GeTInfo(系统) - 返回多个记录 - 数据集

GeTInfo(系统,键) - 返回多条记录 - 数据集

GeTInfo(系统,键,值) - 返回1条记录 - 返回字符串

新方法:

- 我创建了3个属性

- 我删除了函数中的parms它看起来像GetInfo()


功能:

GetInfo ()


3属性:

public String System {get;组; }

public String Key {get;组; } $ / $
public String Value {get;组; }


方法:

我的aspx页面应该设置属性,它可以只是系统或它可以

是系统,键或它可以是系统,键,值。然后调用

GetInfo()函数。我遇到的问题是:如何判断我的

SQL在WHERE子句中应该是什么样子。因为之前的程序

我将它们作为参数传递,然后在WHERE中使用它们。但是我有了b $ b 3函数然后(重载方法)...现在我有1个方法......但是

我怎么能决定我的SQL Where子句应该怎么样喜欢?


选择姓名,地址,邮政编码FROM AddressBOOK XXXXXXXXXXXXXX

是if if(propertySystem!= null){// concat}如果{propertyKey !=

null){// concat}

等等


有人可以显示OOP方法???? ??或者最佳实践......

提前感谢,


mesut

hi colleagues,

I don''t know if this is the right group for but it''s in C# so I try.
I have a #3 procedural function called GetInfo.. and those are 3
overloaded methods. I would like to use the OOP approach to refactor
this.

The functions are working fine but I would like to have a OOP approach
can someone help me refactoring this??????

GeTInfo(System) -returns mutiple records - Dataset
GeTInfo(System,Key) -returns multiple records - Dataset
GeTInfo(System,Key,Value) -returns 1 record - Returns String
new approach:
- I created 3 properties
- I deleted the parms in the Functions it looks like GetInfo()

Function:
GetInfo()

3 Properties:
public String System{ get; set; }
public String Key{ get; set; }
public String Value{ get; set; }

Approach:
my aspx page should set the property, it can just the System or it can
be System, Key or it can be System, Key , Value. and then call the
GetInfo() function. The problem I have is: how can I decide how my
SQL should look like in WHERE clause. Because the previous procedural
I passed them as parameter and then used them in the WHERE. But I had
3 functions then (overloaded Methods)... Now I have 1 method... but
how can I decided how my SQL the Where clause should look like?

SELECT Name, Address, Zipcode FROM AddressBOOK where XXXXXXXXXXXXXX
is it with if (propertySystem!= null) { //concat } If {propertyKey!=
null) {//concat}
etc etc.

can someone show the OOP approach?????? or the best practice...
thanks in advance,

mesut

推荐答案

我的初步问题是为什么没有三个重载方法?

GetInfo(系统)

{

GetInfo(系统,null, null);

}


GetInfo(系统,密钥)

{

GetInfo(系统) ,Key,null);

}


GetInfo(系统,密钥,信息)

{

...做代码的东西...

}

但是,如果你必须继续当前的课程,那么我会建立

属性访问器中的WHERE子句。


公共字符串系统

{

get {}

set

{

_WhereClause + ="和System =''" +值+"''" ;;

}

}


或其他一些东西。或者在调用GetInfo方法时构建可以连接成一个WHERE子句的成员字符串。


希望有所帮助,

Tom P.

7月23日12:05 * pm,mesut< mesut.de ... @ noveonbe.comwrote:
My initial question is why not have the three overloaded methods?
GetInfo(System)
{
GetInfo(System, null, null);
}

GetInfo(System, Key)
{
GetInfo(System, Key, null);
}

GetInfo(System, Key, Info)
{
... do code things...
}
But, if you must continue on your current course then I''d build the
WHERE clause in the property accessor.

public string System
{
get{ }
set
{
_WhereClause += " and System = ''" + value +"''";
}
}

or some such thing. Or build member strings that can be concatenated
into a WHERE clause when the GetInfo method is called.

Hope that helps,
Tom P.
On Jul 23, 12:05*pm, mesut <mesut.de...@noveonbe.comwrote:

hi同事,


我不知道这是不是合适的团队,但它是在C#中所以我试试。

我有一个名为GetInfo的#3程序函数..那些是3

重载方法。我想使用OOP方法来重构

这个。


功能正常但我希望采用OOP方法

有人可以帮我重构吗??????

GeTInfo(系统) - 返回多个记录* - 数据集

GeTInfo(系统) ,键)* - 返回多个记录* - 数据集

GeTInfo(系统,键,值)* - 返回1记录 - 返回字符串


新方法:

- 我创建了3个属性

- 我删除了函数中的parms它看起来像GetInfo()


功能:

GetInfo()


3属性:

public String System {get;组; }

public String Key {get;组; } $ / $
public String Value {get;组; }


方法:

我的aspx页面应该设置属性,它可以只是系统或它可以

是系统,键*或它可以是系统,键,值。 *然后调用

GetInfo()函数。我遇到的问题是:*如何判断我的

SQL在WHERE子句中应该是什么样子。因为之前的程序

我将它们作为参数传递,然后在WHERE中使用它们。但是我有了b $ b 3函数然后(重载方法)...现在我有1个方法......但是

我怎么能决定我的SQL Where子句应该怎么样喜欢?


SELECT Name,Address,Zipcode FROM AddressBOOK XXXXXXXXXXXXXX


是if if(propertySystem!= null){// concat *} *如果{propertyKey!=

null){// concat}

等等


有人可以显示OOP方法??????或者最佳实践...


提前感谢,


mesut
hi colleagues,

I don''t know if this is the right group for but it''s in C# so I try.
I have a #3 procedural function called GetInfo.. and those are 3
overloaded methods. I would like to use the OOP approach to refactor
this.

The functions are working fine but I would like to have a OOP approach
can someone help me refactoring this??????

GeTInfo(System) -returns mutiple records *- Dataset
GeTInfo(System,Key) *-returns multiple records *- Dataset
GeTInfo(System,Key,Value) *-returns 1 record - Returns String

new approach:
- I created 3 properties
- I deleted the parms in the Functions it looks like GetInfo()

Function:
GetInfo()

3 Properties:
public String System{ get; set; }
public String Key{ get; set; }
public String Value{ get; set; }

Approach:
my aspx page should set the property, it can just the System or it can
be System, Key *or it can be System, Key , Value. *and then call the
GetInfo() function. The problem I have is: *how can I decide how my
SQL should look like in WHERE clause. Because the previous procedural
I passed them as parameter and then used them in the WHERE. But I had
3 functions then (overloaded Methods)... Now I have 1 method... but
how can I decided how my SQL the Where clause should look like?

SELECT Name, Address, Zipcode FROM AddressBOOK where XXXXXXXXXXXXXX

is it with if (propertySystem!= null) { //concat *} *If {propertyKey!=
null) {//concat}
etc etc.

can someone show the OOP approach?????? or the best practice...

thanks in advance,

mesut


public string System
public string System

{

get {}

set

{

_WhereClause + ="和System =''" +值+"''" ;;

}

}


或其他一些东西。或者,在调用GetInfo方法时,可以将成员字符串连接成一个WHERE子句。
{
get{ }
set
{
_WhereClause += " and System = ''" + value +"''";
}
}

or some such thing. Or build member strings that can be concatenated
into a WHERE clause when the GetInfo method is called.



认为您的SQL属于应用程序(-10分)

通过连接构建SQL(-10分)

引用输入值而不是使用参数化查询(-100分)

将用户暴露给SQL注入攻击 - 无价


Thinking your SQL belongs in the application (-10 points)
Building SQL by concatenation (-10 points)
Quoting input values instead of using parameterized queries (-100 points)
Exposing your users to SQL injection attack -- priceless


On 7月23日,12:42 * pm,Ben Voigt [C ++ MVP] < r ... @nospam.nospamwrote:
On Jul 23, 12:42*pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:

public string System

{

* * get {}

* * set

* * {

* * * * _WhereClause + ="和System =''" +值+"''" ;;

* *}

}
public string System
{
* * get{ }
* * set
* * {
* * * * _WhereClause += " and System = ''" + value +"''";
* * }
}


或某些这样的事情。或者,在调用GetInfo方法时,可以将成员字符串连接成一个WHERE子句。
or some such thing. Or build member strings that can be concatenated
into a WHERE clause when the GetInfo method is called.



认为您的SQL属于应用程序(-10分)

通过连接构建SQL(-10分)

引用输入值而不是使用参数化查询(-100分)

将用户暴露给SQL注入攻击 - 无价


Thinking your SQL belongs in the application (-10 points)
Building SQL by concatenation (-10 points)
Quoting input values instead of using parameterized queries (-100 points)
Exposing your users to SQL injection attack -- priceless



很公平,但他问道。我还在努力找出为什么功能

重载不是OOP。


Tom P.

Fair enough, but he asked. I''m still trying to find out why function
overloading is not OOP.

Tom P.

这篇关于使这个C#程序函数成为一个OOP函数 - 摆脱参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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