473,625 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1634
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...@no veonbe.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.no spamwrote:
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
"Overloadin g 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)
"Overloadin g 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.
"Overloadin g 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(perso nID) -
>returning a dataset or a list ---- OR -----
2a) create a property in Person class and name it : PropertyPersonI D()
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 'propertyFirstN ame' and 'propertyLastNa me' 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

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

Similar topics

6
1255
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 the initilization
4
4452
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 will allow me, which I *think* it;s 7.1 something, I don't know how to figure out the postgres version. Anywho - I'm trying to backup my databases, which I did at one point, but I have no idea what happened, could have been an upgrade. My Dbs...
2
1493
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 down D. Compartmentalize chunks of code that serve some specific purpose into functions, while filling in the framework left by the top- down approach. E. Refactor until I can call it pretty much done.
13
1595
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 "procedural" manner (without webcontrols and without utilizing OOP concepts in general) produces code that is remarkably faster and more scalable. In general a "bare ASP.NET" application outruns it's OOPy counterpart by factors of 2 to 10. ...
16
4385
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 OOP. Please excuse my poor english too. I hope it's sufficient to explain my question. Generally OOP is better than procedural, but in a case I'm working on, I'm not sure. This is an example of my doubts. I'm writing a simple GUI openGL based.
4
1391
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 sense of programming basics and 1 week familiarizing myself with Python world. Use WinXP. Got Python 2.5. Fooled around in IDLE, made "hello world!" and one which takes user input and tracks a string or two. Project: ambitious GUI program for...
4
2770
by: Mohitz | last post by:
Any pointers as to how one should go about porting procedural type code into object oriented code?? --- Mohit
2
5729
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 cursor and also how to see the output. 2) tell me , the analytic functions in oracle connect by prior, sys_connect_by_path are existed in postgreSQL? 3)how to call the stored procedural function which was written in postgres in java?
0
2795
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 (SELECT COL3 FROM TABLE2) I want to do this in procedural SQL, but I only want to use one cursor. So to do this I have declared a cursor for selecting COL2 from TABLE1 into a variable v_COL2 and am using a loop to iterate over the values....
0
8251
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7178
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.