Hello All:
I work at an insurance company and we are changing the design of an ASP.NET
application (for those have followed my postings, we're going to redesign
some parts of the application - thank you Kevin and Bruce!). The application
processes claims. We have two types of claims, PClaim and WClaim (property
claims and worker's comp claims). PClaim and WClaim share some common traits
so I can have them inherit from an abstract Claim class and not have to worry
about implementing these in the PClaim and WClaim classes.
PClaim and WClaim also have some differing traits. So I can define in each
of their classes the properties and methods that are particular to each type
of claim. So far, so good.
Implementing this, I find:
Dim myClaim As New PClaim
myClaim.whateve r() //shows properties and methods for Claim and
PClaim
Dim myClaim As New Claim
myClaim.whateve r() //shows properties and methods for Claim only
But when I do this, I don't see any of the properties or methods defined in
PClaim or WClaim.
Can someone help me to understand why this is and how I could restructure
this to get what I want.
I would like to design this so that a PClaim or a WClaim can be generically
treated as a Claim and have the claim carry it's claim type (i.e.
myClaim.ClaimTy pe = ClaimType.Prope rty or myClaim.ClaimTy pe =
ClaimType.Worke rsComp) so that the business layer can retrieve the claim's
data from the appropriate source (i.e. the business layer class irequests
the claim type from the claim and, depending on the type of claim, retrieves
the claim's info from either a third-party system or a home-grown database).
This way I can avoid having to maintain two seperate calls in the busines
layer to retrieve claim data. In other words I would like to code this:
Function RetrieveClaimIn fo(c as Claim) as Claim
'code checks claim type and retrieves data from appropriate source
'then retrurns Claim with either the appropriate PClaim properties and
methods
'or Claim with either the appropriate WClaim properties and methods
End Function
as opposed to this:
Function RetrievePropert yClaimInfo(c as PClaim) as PClaim
'code retrieves data from appropriate source and returns a PClaim
End Function
Function RetrieveWorkers CompClaimInfo(c as WClaim) as WClaim
'code retrieves data from appropriate source and returns a WClaim
End Function
I would also like to avoid having several places in the UI project where I
would have to code:
If (PropertyClaim) Then
Dim myClaim As New PClaim
Else
Dim myClaim As New WClaim
End If
I would appreciate any help with this.
TiA,
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation 9 1132
Joe,
Since PClaim and WClaim are inheriting Claim, Claim will never be able to
show their properties only its own.
A simple solution to what you want to do would be to give Claim an
enumerated list of claim types:
Enum ClaimTypes
PClaim
WClaim
End Enum
and a public property for setting the claim type:
Private _ClaimType As ClaimTypes
Public Property ClaimType as ClaimTypes
Get
Return _ClaimType
End Get
Set (ByVal Value As ClaimTypes)
_ClaimType = Value
End Set
End Property
Then in PClaim and WClaim use the new constructor to set the claim type:
Public Sub New()
Me.ClaimType = ClaimTypes.PCla im
End Sub
Then when you reference either as the base Claim you may check the property
to see which type it is:
If Claim.ClaimType = ClaimTypes.PCla im Then
'---Do what you want for a PClaim here
Else
'---Do what you want for a WCalime here
End If
If more claim types are involved use a select case instead of the if/then.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:53******** *************** ***********@mic rosoft.com... Hello All:
I work at an insurance company and we are changing the design of an ASP.NET application (for those have followed my postings, we're going to redesign some parts of the application - thank you Kevin and Bruce!). The application processes claims. We have two types of claims, PClaim and WClaim (property claims and worker's comp claims). PClaim and WClaim share some common traits so I can have them inherit from an abstract Claim class and not have to worry about implementing these in the PClaim and WClaim classes.
PClaim and WClaim also have some differing traits. So I can define in each of their classes the properties and methods that are particular to each type of claim. So far, so good.
Implementing this, I find:
Dim myClaim As New PClaim myClaim.whateve r() //shows properties and methods for Claim and PClaim
Dim myClaim As New Claim myClaim.whateve r() //shows properties and methods for Claim only
But when I do this, I don't see any of the properties or methods defined in PClaim or WClaim.
Can someone help me to understand why this is and how I could restructure this to get what I want.
I would like to design this so that a PClaim or a WClaim can be generically treated as a Claim and have the claim carry it's claim type (i.e. myClaim.ClaimTy pe = ClaimType.Prope rty or myClaim.ClaimTy pe = ClaimType.Worke rsComp) so that the business layer can retrieve the claim's data from the appropriate source (i.e. the business layer class irequests the claim type from the claim and, depending on the type of claim, retrieves the claim's info from either a third-party system or a home-grown database). This way I can avoid having to maintain two seperate calls in the busines layer to retrieve claim data. In other words I would like to code this:
Function RetrieveClaimIn fo(c as Claim) as Claim 'code checks claim type and retrieves data from appropriate source 'then retrurns Claim with either the appropriate PClaim properties and methods 'or Claim with either the appropriate WClaim properties and methods End Function
as opposed to this:
Function RetrievePropert yClaimInfo(c as PClaim) as PClaim 'code retrieves data from appropriate source and returns a PClaim End Function
Function RetrieveWorkers CompClaimInfo(c as WClaim) as WClaim 'code retrieves data from appropriate source and returns a WClaim End Function
I would also like to avoid having several places in the UI project where I would have to code:
If (PropertyClaim) Then Dim myClaim As New PClaim Else Dim myClaim As New WClaim End If
I would appreciate any help with this.
TiA, -- Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
How did you define the 'whatever' method?
Define it as overridable. Both PClaim and WClaim override 'whatever' and
have their own implementation. Then when you have a Claim object, and you
call 'whatever' on it, the correct version will be called.
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:53******** *************** ***********@mic rosoft.com... Hello All:
I work at an insurance company and we are changing the design of an ASP.NET application (for those have followed my postings, we're going to redesign some parts of the application - thank you Kevin and Bruce!). The application processes claims. We have two types of claims, PClaim and WClaim (property claims and worker's comp claims). PClaim and WClaim share some common traits so I can have them inherit from an abstract Claim class and not have to worry about implementing these in the PClaim and WClaim classes.
PClaim and WClaim also have some differing traits. So I can define in each of their classes the properties and methods that are particular to each type of claim. So far, so good.
Implementing this, I find:
Dim myClaim As New PClaim myClaim.whateve r() //shows properties and methods for Claim and PClaim
Dim myClaim As New Claim myClaim.whateve r() //shows properties and methods for Claim only
But when I do this, I don't see any of the properties or methods defined in PClaim or WClaim.
Can someone help me to understand why this is and how I could restructure this to get what I want.
I would like to design this so that a PClaim or a WClaim can be generically treated as a Claim and have the claim carry it's claim type (i.e. myClaim.ClaimTy pe = ClaimType.Prope rty or myClaim.ClaimTy pe = ClaimType.Worke rsComp) so that the business layer can retrieve the claim's data from the appropriate source (i.e. the business layer class irequests the claim type from the claim and, depending on the type of claim, retrieves the claim's info from either a third-party system or a home-grown database). This way I can avoid having to maintain two seperate calls in the busines layer to retrieve claim data. In other words I would like to code this:
Function RetrieveClaimIn fo(c as Claim) as Claim 'code checks claim type and retrieves data from appropriate source 'then retrurns Claim with either the appropriate PClaim properties and methods 'or Claim with either the appropriate WClaim properties and methods End Function
as opposed to this:
Function RetrievePropert yClaimInfo(c as PClaim) as PClaim 'code retrieves data from appropriate source and returns a PClaim End Function
Function RetrieveWorkers CompClaimInfo(c as WClaim) as WClaim 'code retrieves data from appropriate source and returns a WClaim End Function
I would also like to avoid having several places in the UI project where I would have to code:
If (PropertyClaim) Then Dim myClaim As New PClaim Else Dim myClaim As New WClaim End If
I would appreciate any help with this.
TiA, -- Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
Thanks. So far this is what I have. Now, how do I instantiate PClaim or
WClaim with this constructor? If I write:
Dim c as Claim = new PClaim(ClaimTyp e.PC)
then I get a Claim object without any of the properties or methods
specifically associated with a PClaim, just the properties or methods
associated with Claim. This wouldn't give me the properties that I would
want to populate for a PClaim.
On the other hand, if I code:
Dim c as PClaim = new PClaim(ClaimTyp e.PC)
then I get the properties and methods of PClaim (which include the
properties and methods of the Claim). This would give me the type of claim
that I want, but will not allow me to create a single Business layer method
to encapsulate the data retrieveal:
'in Business layer
Public Function RetrieveClaimIn fo(c as Claim) as Claim
If c.ClaimType = ClaimTypes.PCla im Then
'populate PClaim properties
Return PClaim
Else
''populate WClaim properties (many of which are different that
PClaim props)
Return WClaim
End If
End Function
I had hoped for one Business layer function that returns a claim, whether
the claim is a PClaim or a WClaim. I just don't know if this is possible.
It appears that I need two Business layer methods; one that would accept and
return each type of claim. If I had three types of claims, I would need
three Business layer methods, etc.
Have I missed something or do you agree?
Thanks,
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"S. Justin Gengo" wrote: Joe,
Since PClaim and WClaim are inheriting Claim, Claim will never be able to show their properties only its own.
A simple solution to what you want to do would be to give Claim an enumerated list of claim types:
Enum ClaimTypes PClaim WClaim End Enum
and a public property for setting the claim type:
Private _ClaimType As ClaimTypes
Public Property ClaimType as ClaimTypes Get Return _ClaimType End Get Set (ByVal Value As ClaimTypes) _ClaimType = Value End Set End Property
Then in PClaim and WClaim use the new constructor to set the claim type:
Public Sub New() Me.ClaimType = ClaimTypes.PCla im End Sub
Then when you reference either as the base Claim you may check the property to see which type it is:
If Claim.ClaimType = ClaimTypes.PCla im Then '---Do what you want for a PClaim here
Else '---Do what you want for a WCalime here
End If
If more claim types are involved use a select case instead of the if/then.
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order." Nietzsche "Joe" <jo******@donot spam.yahoo.com> wrote in message news:53******** *************** ***********@mic rosoft.com... Hello All:
I work at an insurance company and we are changing the design of an ASP.NET application (for those have followed my postings, we're going to redesign some parts of the application - thank you Kevin and Bruce!). The application processes claims. We have two types of claims, PClaim and WClaim (property claims and worker's comp claims). PClaim and WClaim share some common traits so I can have them inherit from an abstract Claim class and not have to worry about implementing these in the PClaim and WClaim classes.
PClaim and WClaim also have some differing traits. So I can define in each of their classes the properties and methods that are particular to each type of claim. So far, so good.
Implementing this, I find:
Dim myClaim As New PClaim myClaim.whateve r() //shows properties and methods for Claim and PClaim
Dim myClaim As New Claim myClaim.whateve r() //shows properties and methods for Claim only
But when I do this, I don't see any of the properties or methods defined in PClaim or WClaim.
Can someone help me to understand why this is and how I could restructure this to get what I want.
I would like to design this so that a PClaim or a WClaim can be generically treated as a Claim and have the claim carry it's claim type (i.e. myClaim.ClaimTy pe = ClaimType.Prope rty or myClaim.ClaimTy pe = ClaimType.Worke rsComp) so that the business layer can retrieve the claim's data from the appropriate source (i.e. the business layer class irequests the claim type from the claim and, depending on the type of claim, retrieves the claim's info from either a third-party system or a home-grown database). This way I can avoid having to maintain two seperate calls in the busines layer to retrieve claim data. In other words I would like to code this:
Function RetrieveClaimIn fo(c as Claim) as Claim 'code checks claim type and retrieves data from appropriate source 'then retrurns Claim with either the appropriate PClaim properties and methods 'or Claim with either the appropriate WClaim properties and methods End Function
as opposed to this:
Function RetrievePropert yClaimInfo(c as PClaim) as PClaim 'code retrieves data from appropriate source and returns a PClaim End Function
Function RetrieveWorkers CompClaimInfo(c as WClaim) as WClaim 'code retrieves data from appropriate source and returns a WClaim End Function
I would also like to avoid having several places in the UI project where I would have to code:
If (PropertyClaim) Then Dim myClaim As New PClaim Else Dim myClaim As New WClaim End If
I would appreciate any help with this.
TiA, -- Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
the easiest in the UI layer have a methods
void ProcessClaim(WC laim claim)
{
// do wc claim
}
void ProcessClaim(PC laim)
{
// do p cliam
}
void ProcessClaimCom mon(Claim claim)
{
// do common stuff
}
the in the UI
Claim claim = BI.NewClaim(); // returns a PCLaim or WClaim
ProcessClaimCom mon(claim); // do common
ProcessClaim(cl aim); // do specific
-- bruce (sqlwork.com)
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:53******** *************** ***********@mic rosoft.com... Hello All:
I work at an insurance company and we are changing the design of an ASP.NET application (for those have followed my postings, we're going to redesign some parts of the application - thank you Kevin and Bruce!). The application processes claims. We have two types of claims, PClaim and WClaim (property claims and worker's comp claims). PClaim and WClaim share some common traits so I can have them inherit from an abstract Claim class and not have to worry about implementing these in the PClaim and WClaim classes.
PClaim and WClaim also have some differing traits. So I can define in each of their classes the properties and methods that are particular to each type of claim. So far, so good.
Implementing this, I find:
Dim myClaim As New PClaim myClaim.whateve r() //shows properties and methods for Claim and PClaim
Dim myClaim As New Claim myClaim.whateve r() //shows properties and methods for Claim only
But when I do this, I don't see any of the properties or methods defined in PClaim or WClaim.
Can someone help me to understand why this is and how I could restructure this to get what I want.
I would like to design this so that a PClaim or a WClaim can be generically treated as a Claim and have the claim carry it's claim type (i.e. myClaim.ClaimTy pe = ClaimType.Prope rty or myClaim.ClaimTy pe = ClaimType.Worke rsComp) so that the business layer can retrieve the claim's data from the appropriate source (i.e. the business layer class irequests the claim type from the claim and, depending on the type of claim, retrieves the claim's info from either a third-party system or a home-grown database). This way I can avoid having to maintain two seperate calls in the busines layer to retrieve claim data. In other words I would like to code this:
Function RetrieveClaimIn fo(c as Claim) as Claim 'code checks claim type and retrieves data from appropriate source 'then retrurns Claim with either the appropriate PClaim properties and methods 'or Claim with either the appropriate WClaim properties and methods End Function
as opposed to this:
Function RetrievePropert yClaimInfo(c as PClaim) as PClaim 'code retrieves data from appropriate source and returns a PClaim End Function
Function RetrieveWorkers CompClaimInfo(c as WClaim) as WClaim 'code retrieves data from appropriate source and returns a WClaim End Function
I would also like to avoid having several places in the UI project where I would have to code:
If (PropertyClaim) Then Dim myClaim As New PClaim Else Dim myClaim As New WClaim End If
I would appreciate any help with this.
TiA, -- Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
Hi Bruce,
How does Claim claim = BI.NewClaim() return a PClaim or a WClaim? It
returns a Claim. Since, PClaim inherits from Claim and WClaim inherits from
Claim, if I return a Claim, I'll only get the propertiers implemented in
Claim but will loose the specific properties implemented in PClaim or WClaim.
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"Bruce Barker" wrote: the easiest in the UI layer have a methods
void ProcessClaim(WC laim claim) { // do wc claim } void ProcessClaim(PC laim) { // do p cliam } void ProcessClaimCom mon(Claim claim) { // do common stuff }
the in the UI
Claim claim = BI.NewClaim(); // returns a PCLaim or WClaim ProcessClaimCom mon(claim); // do common ProcessClaim(cl aim); // do specific
-- bruce (sqlwork.com) "Joe" <jo******@donot spam.yahoo.com> wrote in message news:53******** *************** ***********@mic rosoft.com... Hello All:
I work at an insurance company and we are changing the design of an ASP.NET application (for those have followed my postings, we're going to redesign some parts of the application - thank you Kevin and Bruce!). The application processes claims. We have two types of claims, PClaim and WClaim (property claims and worker's comp claims). PClaim and WClaim share some common traits so I can have them inherit from an abstract Claim class and not have to worry about implementing these in the PClaim and WClaim classes.
PClaim and WClaim also have some differing traits. So I can define in each of their classes the properties and methods that are particular to each type of claim. So far, so good.
Implementing this, I find:
Dim myClaim As New PClaim myClaim.whateve r() //shows properties and methods for Claim and PClaim
Dim myClaim As New Claim myClaim.whateve r() //shows properties and methods for Claim only
But when I do this, I don't see any of the properties or methods defined in PClaim or WClaim.
Can someone help me to understand why this is and how I could restructure this to get what I want.
I would like to design this so that a PClaim or a WClaim can be generically treated as a Claim and have the claim carry it's claim type (i.e. myClaim.ClaimTy pe = ClaimType.Prope rty or myClaim.ClaimTy pe = ClaimType.Worke rsComp) so that the business layer can retrieve the claim's data from the appropriate source (i.e. the business layer class irequests the claim type from the claim and, depending on the type of claim, retrieves the claim's info from either a third-party system or a home-grown database). This way I can avoid having to maintain two seperate calls in the busines layer to retrieve claim data. In other words I would like to code this:
Function RetrieveClaimIn fo(c as Claim) as Claim 'code checks claim type and retrieves data from appropriate source 'then retrurns Claim with either the appropriate PClaim properties and methods 'or Claim with either the appropriate WClaim properties and methods End Function
as opposed to this:
Function RetrievePropert yClaimInfo(c as PClaim) as PClaim 'code retrieves data from appropriate source and returns a PClaim End Function
Function RetrieveWorkers CompClaimInfo(c as WClaim) as WClaim 'code retrieves data from appropriate source and returns a WClaim End Function
I would also like to avoid having several places in the UI project where I would have to code:
If (PropertyClaim) Then Dim myClaim As New PClaim Else Dim myClaim As New WClaim End If
I would appreciate any help with this.
TiA, -- Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
Joe,
You want to get back a claim, but then test that claim object via it's claim
type property and cast it as the claim you want to work with:
Dim Claim as Claim = MyClaim
Dim PClaim As PClaim
Dim WClaim As WClaim
If Claim.ClaimType = ClaimType.PClai m Then
PClaim = CType(Claim, PClaim)
Else
WClaim = CType Claim, WClaim)
End If
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Joe" <jo******@donot spam.yahoo.com> wrote in message
news:A1******** *************** ***********@mic rosoft.com... Thanks. So far this is what I have. Now, how do I instantiate PClaim or WClaim with this constructor? If I write:
Dim c as Claim = new PClaim(ClaimTyp e.PC)
then I get a Claim object without any of the properties or methods specifically associated with a PClaim, just the properties or methods associated with Claim. This wouldn't give me the properties that I would want to populate for a PClaim.
On the other hand, if I code:
Dim c as PClaim = new PClaim(ClaimTyp e.PC)
then I get the properties and methods of PClaim (which include the properties and methods of the Claim). This would give me the type of claim that I want, but will not allow me to create a single Business layer method to encapsulate the data retrieveal:
'in Business layer Public Function RetrieveClaimIn fo(c as Claim) as Claim If c.ClaimType = ClaimTypes.PCla im Then 'populate PClaim properties Return PClaim
Else ''populate WClaim properties (many of which are different that PClaim props) Return WClaim End If
End Function
I had hoped for one Business layer function that returns a claim, whether the claim is a PClaim or a WClaim. I just don't know if this is possible.
It appears that I need two Business layer methods; one that would accept and return each type of claim. If I had three types of claims, I would need three Business layer methods, etc.
Have I missed something or do you agree?
Thanks,
-- Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"S. Justin Gengo" wrote:
Joe,
Since PClaim and WClaim are inheriting Claim, Claim will never be able to show their properties only its own.
A simple solution to what you want to do would be to give Claim an enumerated list of claim types:
Enum ClaimTypes PClaim WClaim End Enum
and a public property for setting the claim type:
Private _ClaimType As ClaimTypes
Public Property ClaimType as ClaimTypes Get Return _ClaimType End Get Set (ByVal Value As ClaimTypes) _ClaimType = Value End Set End Property
Then in PClaim and WClaim use the new constructor to set the claim type:
Public Sub New() Me.ClaimType = ClaimTypes.PCla im End Sub
Then when you reference either as the base Claim you may check the property to see which type it is:
If Claim.ClaimType = ClaimTypes.PCla im Then '---Do what you want for a PClaim here
Else '---Do what you want for a WCalime here
End If
If more claim types are involved use a select case instead of the if/then.
-- Sincerely,
S. Justin Gengo, MCP Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order." Nietzsche "Joe" <jo******@donot spam.yahoo.com> wrote in message news:53******** *************** ***********@mic rosoft.com... > Hello All: > > I work at an insurance company and we are changing the design of an > ASP.NET > application (for those have followed my postings, we're going to > redesign > some parts of the application - thank you Kevin and Bruce!). The > application > processes claims. We have two types of claims, PClaim and WClaim > (property > claims and worker's comp claims). PClaim and WClaim share some common > traits > so I can have them inherit from an abstract Claim class and not have to > worry > about implementing these in the PClaim and WClaim classes. > > PClaim and WClaim also have some differing traits. So I can define in > each > of their classes the properties and methods that are particular to each > type > of claim. So far, so good. > > Implementing this, I find: > > Dim myClaim As New PClaim > myClaim.whateve r() //shows properties and methods for Claim and > PClaim > > Dim myClaim As New Claim > myClaim.whateve r() //shows properties and methods for Claim > only > > But when I do this, I don't see any of the properties or methods > defined > in > PClaim or WClaim. > > Can someone help me to understand why this is and how I could > restructure > this to get what I want. > > I would like to design this so that a PClaim or a WClaim can be > generically > treated as a Claim and have the claim carry it's claim type (i.e. > myClaim.ClaimTy pe = ClaimType.Prope rty or myClaim.ClaimTy pe = > ClaimType.Worke rsComp) so that the business layer can retrieve the > claim's > data from the appropriate source (i.e. the business layer class > irequests > the claim type from the claim and, depending on the type of claim, > retrieves > the claim's info from either a third-party system or a home-grown > database). > This way I can avoid having to maintain two seperate calls in the > busines > layer to retrieve claim data. In other words I would like to code > this: > > Function RetrieveClaimIn fo(c as Claim) as Claim > 'code checks claim type and retrieves data from appropriate source > 'then retrurns Claim with either the appropriate PClaim properties > and > methods > 'or Claim with either the appropriate WClaim properties and methods > End Function > > as opposed to this: > > Function RetrievePropert yClaimInfo(c as PClaim) as PClaim > 'code retrieves data from appropriate source and returns a PClaim > End Function > > Function RetrieveWorkers CompClaimInfo(c as WClaim) as WClaim > 'code retrieves data from appropriate source and returns a WClaim > End Function > > I would also like to avoid having several places in the UI project > where I > would have to code: > > If (PropertyClaim) Then > Dim myClaim As New PClaim > Else > Dim myClaim As New WClaim > End If > > I would appreciate any help with this. > > TiA, > -- > Joe > > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
The real challenge here is that you want a single business layer that
accepts any number of types of claims without creating a business layer
for each type of claim. To accomplish this, you need to understand the
concept of downcasting and upcasting.
(Page 56 - C# In a Nutshell - O'Reilly)
In short any base class can be downcast to a derived class and any
derived class can be upcast to its base class and maintain the data
specific to the derived class.
What this means is that you can create one business layer method that
accepts the base class Claim as it's argument then recasts it back to
its appropriate type in order to retrieve its properties.
For example, given that you have a base class Claim, and derived
classes WClaim and PClaim you can create a single business layer
function and you don't even need any overloaded versions to handle
different claim types...
public Claim DoMyBusiness(Cl aim myClaim) // notice that it accepts the
base (abstract) class as an argument
{
PClaim myPClaim;
WClaim myClaim;
// first determine what type myClaim is...
if (myClaim.GetTyp e() == typeof(PClaim)) // if this is a PClaim
then...
myPClaim = (PClaim)myClaim ; // ...cast myClaim to a PClaim
(downcast)
else if (myClaim.GetTyp e() == typeof(WClaim)) // if this is a WClaim
then...
myWClaim = (WClaim)myClaim ; // ...cast myClaim to a WClaim
(downcast)
// note: to compare types in vb use...
// If TypeOf myClaim is WClaim Then
// now that I've recast myClaim to its proper claim type I can
retrieve the properties specific to that claim type that were set in
the calling function.
if (PClaim != null)
{ //get a PClaim using properties specific to a PClaim}
else if (WClaim != null)
{ get a WClaim using... }
// next, do something thats generic to all claim types, I.e. my
general business layer stuff
// if this general business logic is common to all claim types and
uses only properties of the base class
// then you could either refer back to myClaim or upcast the
retrieved claim back to a Claim.
// that way you don't have to have a bunch of code to check what type
of claim it is.
// finally return either PClaim or WClaim
// Its important to note that even though DoMyBusiness returns an
object of type Claim,
// you can also return objects of type PClaim or WClaim because they
are derived from Claim
// Also, when that object is returned back to the calling function it
is automatically downcast
// which means that it will be returned as the proper claim type with
all properties specific to the claim type
if (PClaim != null)
{ return PClaim }
else if (WClaim != null)
{ return WClaim}
}
I just realized that I have a couple of typos.
Please use the following corrections:
if (myPClaim != null)
{ //get a PClaim using properties specific to a PClaim}
else if (myWClaim != null)
{ get a WClaim using... }
if (myPClaim != null)
{ return myPClaim }
else if (myWClaim != null)
{ return myWClaim}
Typeos noted.
Thank you very much. This is exactly what I was looking for.
--
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"ms*****@hotmai l.com" wrote: I just realized that I have a couple of typos. Please use the following corrections:
if (myPClaim != null) { //get a PClaim using properties specific to a PClaim} else if (myWClaim != null) { get a WClaim using... }
if (myPClaim != null) { return myPClaim } else if (myWClaim != null) { return myWClaim}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: KK |
last post by:
Windows Forms Inheritance, Incomplete?
I was playing around with Windows Forms
and found out this Forms Inheritance feature.
The moment I saw that, I felt this can be
used effectively if the application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between the forms.
|
by: KK |
last post by:
** Posting it here cause after couple of days no body responded.**
I was playing around with Windows Forms
and found out this Forms Inheritance feature.
The moment I saw that, I felt this can be
used effectively if the application
contains couople of forms which have
a consistant look and also shares
SOME similar functionality between the forms.
|
by: Dave Theese |
last post by:
Hello all,
The example below demonstrates proper conformance to the C++ standard.
However, I'm having a hard time getting my brain around which language rules
make this proper...
The error below *should* happen, but my question to the community is *why*
does it happen? Any answer will be appreciated, but a section and paragraph
number from the C++ Standard would be especially appreciated.
|
by: __PPS__ |
last post by:
Hello everybody, today I had another quiz question
"if class X is privately derived from base class Y what is the scope of
the public, protected, private members of Y will be in class X"
By scope they meant public/protected/private access modifiers :)
Obviously all members of the base privately inherited class will be
private, and that was my answer. However, the teacher checked my
answers when I handed in, and the problem was that I had...
|
by: Matthew Louden |
last post by:
I want to know why C# doesnt support multiple inheritance? But why we can
inherit multiple interfaces instead? I know this is the rule, but I dont
understand why. Can anyone give me some concrete examples?
| |
by: Ben Blank |
last post by:
I'm writing a family of classes which all inherit most of their methods and
code (including constructors) from a single base class. When attempting to
instance one of the derived classes using parameters, I get CS1501 (no method
with X arguments). Here's a simplified example which mimics the
circumstances:
namespace InheritError {
// Random base class.
public class A {
protected int i;
|
by: VR |
last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some
WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages,
my MasterPage does not have a form tag itself so, cannot be called a WebForm
itself, the child pages will implement forms).
I created a Master.aspx page and removed all HTML from it, added some code
to the .aspx.vb file to add controls to my page. Then I created a Child.aspx
and changed the...
|
by: Noah Roberts |
last post by:
Is there anything that says that if you virtually inherit from one
class you have to virtually inherit from anything you inherit from?
|
by: RSH |
last post by:
I have a simple question regarding inheritance in a web form.
I have a DropDownList in an aspx form. It is called DropDownList1
I have a class that will be overriding the render event so I have a snippet
of this class:
Public Class CustomDDL
Inherits DropDownList
|
by: RSH |
last post by:
Hi,
I am working on some general OOP constructs and I was wondering if I could
get some guidance.
I have an instance where I have a Base Abstract Class, and 4 Derived
classes. I now need to make a list class that will store the objects. My
question is how do I go about creating the list class...I am assuming it
should be a standalone class that uses an arraylist to store the objects.
If I go that route how do I instantiate the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
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...
| |
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |