Results 1 to 7 of 7

Thread: Question about class properties

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    7

    Question about class properties

    Is this possible and if so how do I do it? I want to create 3 classes, ItemType, Manufacturer, and Item. I want to give ItemType and Manufacturer codes so that they can be combined into a code for the Item. Is there a way to define the property to be a string that is the desired concatenation? Do I need to create a method, or hard code the value definition in the app? How do I do this so that the value is updated based on the user selecting ItemType and Manufacturer from dropdown lists and adding the ItemName string?


    Code:
    Public Class ItemType
       Public Property ID as Integer
       Public Property ItemTypeName as String
       Public Property ItemTypeCode as String
    End Class
    Code:
    Public Class Manufacturer
       Public Property ID as Integer
       Public Property ManufacturerName as String
       Public Property ManufacturerCode as String
    End Class
    Code:
    Public Class Item
       Public Property ID as Integer
       Public Property ItemTypeID as Integer
       Public Property ItemType as ItemType
       Public Property ManufactuerID as Integer
       Public Property Manufactuer as Manufacturer
       Public Property ItemName as String
       Public Property ItemCode as String (want this to be a concatenation of the ItemTypeCode and the ManufacturerCode)
    End Class

  2. #2
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Question about class properties

    You can instantiate both classes from the two different classes, or inherit from the two different classes. And go on from there.

  3. #3
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Question about class properties

    It should look like this.

    Code:
    Public Class ItemType
        Public Property ID As Integer
        Public Property ItemTypeName As String
        Public Property ItemTypeCode As String
    End Class
    
    Public Class Manufacturer
        Public Property ID As Integer
        Public Property ManufacturerName As String
        Public Property ManufacturerCode As String
    End Class
    
    Public Class Item
        Public Property ID As Integer
        Public Property ItemTypeID As Integer
        Public Property ItemType As ItemType
        Public Property ManufactuerID As Integer
        Public Property Manufactuer As Manufacturer
        Public Property ItemName As String
    
        Private _ItemCode As String
        Public Property ItemCode As String
            Get
                Dim itemType As New ItemType
                Dim manufacturer As New Manufacturer
    
                Return itemType.ItemTypeCode & manufacturer.ManufacturerCode
            End Get
            Set(value As String)
                _ItemCode = value
            End Set
        End Property
    End Class

    But things like this is normally done best with the use of SQL tables etc.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,237

    Re: Question about class properties

    Why do you have ItemTypeID and ManufacturerID in the Item class? Are those not members of the ItemType and Manufacturer classes already, in which case they shouldn't be dupicated in the Item?
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    7

    Re: Question about class properties

    Thank you, and you nailed it. This is a project i am working on trying to learn MVC and SQL Server. So are you saying to add that to my code and leave the field off the Create form, or let SQL server concatenate it and leave the property as just a string?

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2014
    Posts
    7

    Re: Question about class properties

    They are set that way so Entity Framework creates dropdown lists in the MVC project i am working on.

  7. #7
    Fanatic Member Toph's Avatar
    Join Date
    Oct 2014
    Posts
    655

    Re: Question about class properties

    No I'm saying this would be better done with the use of SQL tables. It's the most efficient and professional way to handle this. Using this in a object oriented technique is not much of a good idea. If you had used SQL tables. You can easily form a relational tables and whatnot and easily extract data.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width