Interface and collection

Last post 05-03-2006 9:17 AM by therubble. 4 replies.

Sort Posts:

  • Interface and collection

    05-02-2006, 6:08 PM
    • Member
      146 point Member
    • therubble
    • Member since 12-08-2004, 2:32 AM
    • Norwich
    • Posts 32

    I have in interface called iproduct, that needs to define that a collection needs to be implemented how is this done.

    Public

    Interface iProduct

    Property ProductID() As Integer

    Property Quantity() As Integer

    Property Price() As Decimal

    End

    Interface

    Or would it just be done in the class that implements the interface, i'm trying to build a fully OO shooping cart for some sites that I gotta build.

     

     

     

    Pushing out shapes, to a popular beat combo.
  • Re: Interface and collection

    05-02-2006, 11:26 PM
    • Participant
      875 point Participant
    • James Steele
    • Member since 04-27-2006, 12:08 AM
    • Posts 173

    Hi,

    How about: 

    Public Interface iProduct
    
        Property someCollection() As ICollection
    
        Property ProductID() As Integer
    
        Property Quantity() As Integer
    
        Property Price() As Decimal
    
    End Interface  
    Public Class Product
        Implements iProduct
    
        Public Property someCollection() As System.Collections.ICollection Implements iProduct.someCollection
            Get
    
            End Get
            Set(ByVal value As System.Collections.ICollection)
    
            End Set
        End Property
    James Steele
  • Re: Interface and collection

    05-03-2006, 4:02 AM
    • Member
      146 point Member
    • therubble
    • Member since 12-08-2004, 2:32 AM
    • Norwich
    • Posts 32
    Whenever I try and access the collection, I get an object instance not set error? Am i doing something stupid.
    Pushing out shapes, to a popular beat combo.
  • Re: Interface and collection

    05-03-2006, 8:14 AM
    • All-Star
      97,373 point All-Star
    • mbanavige
    • Member since 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 10,287
    • Moderator
      TrustedFriends-MVPs

    Having the shopping cart collection inside of the product seems to be a case of the cart before the horse...no pun intended. If you have two products, do they each contain their own shiopping cart collection?

    I do not believe you would want the item interface to contain the shopping cart interface.

    Products are products - not collections
    The shopping cart is a collection of Products.
    In .Net 2.0, you could express that collection with Generics.
    In .Net 1.1, you could create a ShoppingCart class that inherits from CollectionBase.
    Then you add type specific access methods so the cart only accepts Products.

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Interface and collection

    05-03-2006, 9:17 AM
    • Member
      146 point Member
    • therubble
    • Member since 12-08-2004, 2:32 AM
    • Norwich
    • Posts 32

    I was thinking that a product would contain a collection of additional definable properties, eg
    If the product as a t-shirt you could define size and color.
    Hence a collection inside of the product.

    Pushing out shapes, to a popular beat combo.
Page 1 of 1 (5 items)