Abstract Business Object


Author
Message
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
I would like to have a Base BO from which I inherit a bunch of similar BOs that just have different properties, and attach to different tables in the db.  I would like to have a set of MustOverride type properties, so that I can have sort of a template for the inherited BOs.  I have done this, which causes the Base class to be abstract.  Then,  in the inherited BO, I change the Inherits MicroFour.StrataFrame.Business.BusinessLayer to Inherits BBS.Biz.Base.TableBO in my inherited class (including the partial).  Everything works great except that when I want to pull up the design view for the Inherited BO it gives me this error:

The designer must create an instance of type 'BBS.Biz.Base.TableBO' but it cannot because the type is declared as abstract.

Is there any way to get around this, or is there a better way to accomplish what I'm trying to do here?

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Andria,

This is actually coming from .NET.  You cannot instantiate an abtract class and is for inhertiance only.  That is why you are receiving the error.  What you might want to do is create an interface and then implement the interface on the BO.  An interface allows you to define all of your abstract properties and the implement it on any class.  Also, if the properties, methods, etc., are not "implemented" on the class it will not compile.  This provides the same basic functionality of an abstract class but ultimately gives you more options.  Below is an example:

Public Interface MyInterface
    '-- Define Properties
    Property MyProperty() As String

    '-- Define Methods
    Sub MyMethod()

End Interface

Public Class MyClass
   
Implements MyInterface

    Public Sub MyMethod() Implements MyInterface.MyMethod

    End Sub

    Public Property MyProperty() As String Implements MyInterface.MyProperty
       
Get

        End Get
       
Set(ByVal value As String)

        End Set
   
End Property

End Class


Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
An interface is fine for properties that I want to have set for each inherited BO.  However, what if I wanted to do something like have the New always call a certain Method to Fill the object?  I can't accomplish this through an interface.  That's why I was looking at an abstract class instead.  Is there anyway I can have a BO as a base with some basic methods the way I'd like them and have other BO's inherit those methods?
Lance Tofsrud
Lance Tofsrud
StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)StrataFrame Beginner (32 reputation)
Group: Forum Members
Posts: 12, Visits: 21
Hi Andria,

Have you thought about inheriting through composition rather than implementation inheritance (which is what traditionally most developers think of)? As Trent mentioned, by programming to an interface rather than an abstract class, you have a lot more options for expansion of your class and don't have to worry about tightly coupling with your base class.

You get around some of the convoluted class heirarchy issues that usually appear when you get on a strict implementation inheritance run as well.  Personally, I find that my code also ends up being easier to read since I don't have to worry as much about which methods are virtual/overridden/etc.

Anyways, just touting the benefits of composition over inheritance and hoping that provides some direction.

Lance

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Andria,

Lance is correct, but technically, if you wanted to create a business object that you wanted to use as a base class for another business object, you certainly could.  All you would have to do is change the Inherits line from BusinessLayer to your business object that implements the code.

Thinking back to the other post, if you wanted to create a business object factory, you could create a generic factory method that would return a new instance of the business object you wanted to create.  So, if the business object implements an interface that contains a property holding the SQL statement you wanted to execute, (let's call it SqlToExecute) then you can create a method like this:

Public Shared Function CreateNewFilledBO(Of T As {BusinessLayer, New})() As T

'-- Establish locals
Dim loReturn As T

'-- Create the new business object
loReturn = New T()

'-- Fill the business object
loReturn.FillDataTable(CType(loReturn, MyInterface).SqlToExecute)

'-- Return the business object
Return loReturn

End Function

Some of this might be pretty advanced, and there's a great deal of information on creating and using generic methods here: http://msdn2.microsoft.com/en-us/library/w256ka79(VS.80).aspx

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search