473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

making this C# procedural function an OOP function - get rid of theparameters

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
Jul 23 '08 #1
14 1611
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 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
Jul 23 '08 #2
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.

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
Jul 23 '08 #3
On Jul 23, 12:42*pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
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.

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
Fair enough, but he asked. I'm still trying to find out why function
overloading is not OOP.

Tom P.
Jul 23 '08 #4
mesut wrote:
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
That is an OOP approach. Overloading is a part of polymorphism, which is
one of the main principles for OOP.

However, if what the methods do differ too much, you should give them
separate names instead. Also, it's somewhat impractical to have
overloads return different data types.
>
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.
That's not a good approach at all. You have gone from an approach where
the method call is self describing, to an approach where it's not.
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

--
Göran Andersson
_____
http://www.guffa.com
Jul 23 '08 #5
That is an OOP approach. Overloading is a part of polymorphism, which
is one of the main principles for OOP.
???

Overridding is related to polymorphism, overloading is not.
Jul 23 '08 #6
Ben Voigt [C++ MVP] wrote:
>That is an OOP approach. Overloading is a part of polymorphism, which
is one of the main principles for OOP.

???

Overridding is related to polymorphism, overloading is not.
Everything that I read says that it is... For example:
"This type of polymorphism is sometimes known as overloading."

http://searchcio-midmarket.techtarge...212803,00.html
"Overloading is one type of polymorphism."

http://www.webopedia.com/TERM/O/overloading.html
"This type of polymorphism is common in object-oriented programming
languages, many of which allow operators to be overloaded in a manner
similar to functions (see operator overloading)."

http://en.wikipedia.org/wiki/Polymor...mputer_science)
"Overloading Polymorphism is the use of one method signature, or one
operator such as "+", to perform several different functions depending
on the implementation."

http://en.wikipedia.org/wiki/Polymor...ed_programming
--
Göran Andersson
_____
http://www.guffa.com
Jul 23 '08 #7
mesut wrote:
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
Oh dear. You've hit "the vietnam of computer science".

Good options are to either drop the idea of using OO here, to use an
automated ORM tool, or use an OODBMS.

Alun Harford
Jul 23 '08 #8
Göran Andersson wrote:
Ben Voigt [C++ MVP] wrote:
>>That is an OOP approach. Overloading is a part of polymorphism, which
is one of the main principles for OOP.

???

Overridding is related to polymorphism, overloading is not.

Everything that I read says that it is... For example:
I think you read a bit selective then.

It should be obvious that it is possible to create
a procedural programming language that has function/subroutine
overloading.
"This type of polymorphism is common in object-oriented programming
languages, many of which allow operators to be overloaded in a manner
similar to functions (see operator overloading)."

http://en.wikipedia.org/wiki/Polymor...mputer_science)
This is under something it calls "Ad-hoc polymorphism". And
it says "Strachey [3] chose the term ad-hoc polymorphism to refer to..."
and the reference 3 is from 1967.
"Overloading Polymorphism is the use of one method signature, or one
operator such as "+", to perform several different functions depending
on the implementation."

http://en.wikipedia.org/wiki/Polymor...ed_programming
I don't think this is talking about what you think it is.

I read it as if a sub class must have the methods and the
operators of the sub class. Which is polymorphism.

Arne
Jul 24 '08 #9
Hi colleagues,

thanks for sharing your thoughts with me.

First of all I think I should explain why I want to move to the
property way iso overloading methods.

I'm not strong in OOP but as far as I did my research (maybe not good
enough)... In OOP principles you work with objects.
and an objects has methods and properties as type.

the situation I have is :
my aspx page in presentation layer is calling the class object in the
Business logic layer. So those are separated.

My idea was if we work with objects then I should set the values in
propertie and then call the methods. Therefore I wished to delete the
parameters and use properties. the situation I have then is setting
the parameter then call the object. Since I've 3 methods doing
similair thing just the WHERE clause should be changed.

This is my statement, correct me if I'm wrong:
USE properties iso parameters in functions as much as I can, because
objects works with properties. A property has a get and set accessor
to check the value you pass. So I think using property is much more
OOP then passing parameters in functions... I guess.

let me give another example.

if you have a person class and method that returns address, city,
country of the that person.
The method is called GetPerson in thet Person class.

Which approach would you use....
1) call with parameter passing the peson ID: GetPerson(personID) -
>returning a dataset or a list ---- OR -----
2a) create a property in Person class and name it : PropertyPersonID()
etc.
2b) set the property value and call this method: GetPerson()

ok.... which is more OOP... I think approach 2 is OOP. I guess...

Ok let's say I only know the person's first name and last name and I
would like to get all persons starting with these info. I would also
like name the method GetPerson. Because it's related to the person.

What I do is create 2 more properties in Person class name the
properties like 'propertyFirstName' and 'propertyLastName' then call
the GetPerson() method....

ok.... how would you handle this ? property approach??????

thanks
-mesut
ps: or would you just create 2 methods and overload them??????????????
Jul 24 '08 #10
mesut wrote:
Hi colleagues,

thanks for sharing your thoughts with me.

First of all I think I should explain why I want to move to the
property way iso overloading methods.

I'm not strong in OOP but as far as I did my research (maybe not good
enough)... In OOP principles you work with objects.
and an objects has methods and properties as type.

the situation I have is :
my aspx page in presentation layer is calling the class object in the
Business logic layer. So those are separated.

My idea was if we work with objects then I should set the values in
propertie and then call the methods. Therefore I wished to delete the
parameters and use properties. the situation I have then is setting
the parameter then call the object. Since I've 3 methods doing
similair thing just the WHERE clause should be changed.

This is my statement, correct me if I'm wrong:
USE properties iso parameters in functions as much as I can, because
objects works with properties. A property has a get and set accessor
to check the value you pass. So I think using property is much more
OOP then passing parameters in functions... I guess.
Not at all. Neither method is more object oriented than the other.

In your attempt to make the code more object oriented, you have actually
managed to make it less object oriented, or at least less managable. If
you have methods with specific parameters, it's obvious by just looking
at the method signatures what you can do with them, and it's not even
possible to call the methods with any other set of data than the
intended. This is robust, managable and thus good. By using properties
and a parameterless method, the code has lost the control over it's
usage, and you can easily call the method with a completely wrong set of
data. The code is not self-documenting any more, and you have to read
the documentation to understand which properties to set to get a
specific result.

If you want it more object oriented, you should have methods that
returns an object or a list of objects, not a DataSet. The object that
everything revolves around should be the data that you fetch, not
something unidentifiable that you use to fetch the data with.

If you don't want to create objects for the data, but want to keep the
data in a DataSet (which is a reasonable compromise), then your code is
pretty much as object oriented as it can get.
let me give another example.

if you have a person class and method that returns address, city,
country of the that person.
The method is called GetPerson in thet Person class.

Which approach would you use....
1) call with parameter passing the peson ID: GetPerson(personID) -
>returning a dataset or a list ---- OR -----
2a) create a property in Person class and name it : PropertyPersonID()
etc.
2b) set the property value and call this method: GetPerson()

ok.... which is more OOP... I think approach 2 is OOP. I guess...
3) A call to GetPerson(personId) returning a Person object.
Ok let's say I only know the person's first name and last name and I
would like to get all persons starting with these info. I would also
like name the method GetPerson. Because it's related to the person.

What I do is create 2 more properties in Person class name the
properties like 'propertyFirstName' and 'propertyLastName' then call
the GetPerson() method....

ok.... how would you handle this ? property approach??????

thanks
-mesut
ps: or would you just create 2 methods and overload them??????????????
--
Göran Andersson
_____
http://www.guffa.com
Jul 24 '08 #11
Arne Vajhřj wrote:
Göran Andersson wrote:
>Ben Voigt [C++ MVP] wrote:
>>>That is an OOP approach. Overloading is a part of polymorphism, which
is one of the main principles for OOP.

???

Overridding is related to polymorphism, overloading is not.

Everything that I read says that it is... For example:

I think you read a bit selective then.
I don't understand how a clear statement like "Overloading is one type
of polymorphism." could possibly be read selectively?

Do you have anything else that I could read?
It should be obvious that it is possible to create
a procedural programming language that has function/subroutine
overloading.
The same is true for any of the OO principles. Just because it could be
implemented in a procedural language, doesn't make it non-OO.
>"This type of polymorphism is common in object-oriented programming
languages, many of which allow operators to be overloaded in a manner
similar to functions (see operator overloading)."

http://en.wikipedia.org/wiki/Polymor...mputer_science)

This is under something it calls "Ad-hoc polymorphism". And
it says "Strachey [3] chose the term ad-hoc polymorphism to refer to..."
and the reference 3 is from 1967.
Yes, OO has been around for a while. Just because something was said a
few years ago, doesn't automatically make it wrong.
>"Overloading Polymorphism is the use of one method signature, or one
operator such as "+", to perform several different functions depending
on the implementation."

http://en.wikipedia.org/wiki/Polymor...ed_programming

I don't think this is talking about what you think it is.

I read it as if a sub class must have the methods and the
operators of the sub class. Which is polymorphism.

Arne
What do you think that I think it is? ;)

I don't see anything in that paragraph that even suggests that is has
anything to do with subclassing.

--
Göran Andersson
_____
http://www.guffa.com
Jul 24 '08 #12
Göran Andersson wrote:
Ben Voigt [C++ MVP] wrote:
>>That is an OOP approach. Overloading is a part of polymorphism,
which is one of the main principles for OOP.

???

Overridding is related to polymorphism, overloading is not.

Everything that I read says that it is... For example:
C'mon, don't you mean, the first batch of search engine hits for "overload
AND polymorphism".

But not all information on the web is accurate.

Polymorphism is all about the LSP and *requires* dynamic dispatch. There
are languages which implement overloading with dynamic dispatch but C# (nor
VB.NET, VB6, Java, JavaScript, non-template C++) are not among them.
Overload resolution in C# is done statically and is therefore not
polymorphic.
Jul 24 '08 #13
Ben Voigt [C++ MVP] wrote:
Göran Andersson wrote:
>Ben Voigt [C++ MVP] wrote:
>>>That is an OOP approach. Overloading is a part of polymorphism,
which is one of the main principles for OOP.
???

Overridding is related to polymorphism, overloading is not.
Everything that I read says that it is... For example:

C'mon, don't you mean, the first batch of search engine hits for "overload
AND polymorphism".
Not at all.
But not all information on the web is accurate.

Polymorphism is all about the LSP and *requires* dynamic dispatch. There
are languages which implement overloading with dynamic dispatch but C# (nor
VB.NET, VB6, Java, JavaScript, non-template C++) are not among them.
Overload resolution in C# is done statically and is therefore not
polymorphic.
You are talking about subtype polymorphism. Just because it's true for
that specific concept, doesn't invalidate all other forms of polymorphism.

Parametric polymorphism, for example, is done by the compiler, so by
your definition it would not be polymorphism at all.

--
Göran Andersson
_____
http://www.guffa.com
Jul 25 '08 #14
thanks everybody. It was a nice discussion I mean I learnt a lot of
jargons. I shall keep my overloaded methods, because it seems to be
that it's right. I shall return List i to use more OOP iso Datasets

thanks, mesut
Jul 25 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: gf gf | last post by:
Is there a better, more FP style, more Pythonic way to write this: def compute_vectors(samples, dset): vectors = {} for d in dset: vectors = return vectors Namely, I'd like to get rid of...
4
by: Mark Mikulec | last post by:
Hi there, I wonder if anyone can shed some light on a very frustrating problem. I'm running a debian linux 3.0 "woody" server, nothing special, with the latest version of postres that apt-get...
2
by: John Gabriele | last post by:
The way I've always "designed" procedural C programs has just been to: A. Think about what I need to do B. Draw a flowchart with pencil and paper C. Implement the flowchart in C from the top...
13
by: parley | last post by:
After several years of programming WWW applications in ASP.NET (and several other frameworks) our division has come to what might seem a counterintiutive conclusion: Writing ASP.NET code in a...
16
by: Manuel | last post by:
Please, excuse me for starting this discussion. I'm not a troll, and I love the OOP architecture. However I'm a C++ newbie, and sometimes it's hard for me to fully understand the improvement of...
4
by: Chelonian | last post by:
I'm considering trying to learn Python for a specific reason, and hoped the group might help me get a sense for whether it would be worth my time. The situation... Me: total beginner w/ a...
4
by: Mohitz | last post by:
Any pointers as to how one should go about porting procedural type code into object oriented code?? --- Mohit
2
by: san1014 | last post by:
Hi I have few questions. Pleae give me the answers. 1) In postgreSQL, how to declare and call the cursors in a stored procedural function? Ex: I want to display all the columns in a table in one...
0
by: FLANDERS | last post by:
Hi all, Is it possible to declare a SQL type of result set or similar? I want to do use the IN predicate like you can in a non-procedural SQL like this: UPDATE TABLE1 SET COL1 = 123 WHERE COL2 IN...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.