Newbie: How to extend a class?

T

Terry Carnes

I have a dotnet assembly which includes classes RequestType, Response,
Transaction, and TransactionElement.

To use this I would normally create a new Transaction passing it a parameter
of RequestType and receive a Transaction object of the right type in return.

Paymentech.Transaction transaction = new
Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE);

I now find myself having to access this assembly in an environment that does
not allow me to pass the RequestType parameter when I create the object
(PHP). To work around this limitation, I would like to create another dotnet
assembly which will basically be way to call all the different types of
Transactions without passing parameters. In other words, I want to create a
separate class for each type of Transaction I need.

So I will end up with a CC_AuthorizeTransaction class, a
CC_CaptureTransaction class, an Ecommerce_RefundTransaction class, etc.

I envision all these classes sitting in my own dotnet assembly.

I think I need to have each of my classes inherit/extend from the
Paymentech.Transaction class only needing to change the constructor.

Here is where I'm lost (not having done this before). How do I do this? Do
I need to do something with all the other members/methods of
Paymentech.Transaction as well?

I apologize that this question is so basic.

Terry
 
P

PS

Terry Carnes said:
I have a dotnet assembly which includes classes RequestType, Response,
Transaction, and TransactionElement.

To use this I would normally create a new Transaction passing it a
parameter of RequestType and receive a Transaction object of the right
type in return.

Paymentech.Transaction transaction = new
Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE);

I now find myself having to access this assembly in an environment that
does not allow me to pass the RequestType parameter when I create the
object (PHP). To work around this limitation, I would like to create
another dotnet assembly which will basically be way to call all the
different types of Transactions without passing parameters. In other
words, I want to create a separate class for each type of Transaction I
need.

So I will end up with a CC_AuthorizeTransaction class, a
CC_CaptureTransaction class, an Ecommerce_RefundTransaction class, etc.

I envision all these classes sitting in my own dotnet assembly.

I think I need to have each of my classes inherit/extend from the
Paymentech.Transaction class only needing to change the constructor.

Here is where I'm lost (not having done this before). How do I do this?
Do I need to do something with all the other members/methods of
Paymentech.Transaction as well?

public class CC_AuthorizeTransaction : Paymentech.Transaction
{
public CC_AuthorizeTransaction()
{
base.RequestType = Paymentech.RequestType.CC_AUTHORIZE;
}
}
 
T

Terry Carnes

base.RequestType = Paymentech.RequestType.CC_AUTHORIZE;

Isn't working. I get the error that 'Paymentech.Transaction' does not
contain a definition for 'RequestType'.

I was expecting something like (in pseudocode):

return object = new
Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE);

The assembly doesn't allow the changing of a RequestType after
instantiation. It needs to know the requested type in its constructor so it
builds the right type of Transaction to begin with.

Terry
 
J

Jon Skeet [C# MVP]

PS said:
public class CC_AuthorizeTransaction : Paymentech.Transaction
{
public CC_AuthorizeTransaction()
{
base.RequestType = Paymentech.RequestType.CC_AUTHORIZE;
}
}

Or even (to keep in line with the previously posted code):

public class CC_AuthorizeTransaction : Paymentech.Transaction
{
public CC_AuthorizeTransaction()
: base (Paymentech.RequestType.CC_AUTHORIZE)
{
}
}
 
P

PS

Terry Carnes said:
base.RequestType = Paymentech.RequestType.CC_AUTHORIZE;

Isn't working. I get the error that 'Paymentech.Transaction' does not
contain a definition for 'RequestType'.

I was expecting something like (in pseudocode):

return object = new
Paymentech.Transaction(Paymentech.RequestType.CC_AUTHORIZE);

The assembly doesn't allow the changing of a RequestType after
instantiation. It needs to know the requested type in its constructor so
it builds the right type of Transaction to begin with.

I was just taking a guess at the internals of the class as an example. Jon's
calling of the base constructor is the only way to do it based on this
knowledge.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top