Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Multiple classes calling another same classs

Multiple classes calling another same classs

Scheduled Pinned Locked Moved Design and Architecture
designregexarchitecture
5 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13988913
    wrote on last edited by
    #1

    I have 10 diffrent classes like a,b,c which have diffrent primary keys and structure but every class will b having a button which will be opening a same class like Charges if gets clicked.
    I want to save charges class information along with the primary Key of the relevant class(a,b,c) from which it gets called.What would be the best design pattern for it. Thanks

    L J 2 Replies Last reply
    0
    • U User 13988913

      I have 10 diffrent classes like a,b,c which have diffrent primary keys and structure but every class will b having a button which will be opening a same class like Charges if gets clicked.
      I want to save charges class information along with the primary Key of the relevant class(a,b,c) from which it gets called.What would be the best design pattern for it. Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You'll need a "class id and instance key" for the "10 different classes" if you want to relate them to a single source of "Charge classes". (bi-directional parent-child relation).

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      A R 2 Replies Last reply
      0
      • U User 13988913

        I have 10 diffrent classes like a,b,c which have diffrent primary keys and structure but every class will b having a button which will be opening a same class like Charges if gets clicked.
        I want to save charges class information along with the primary Key of the relevant class(a,b,c) from which it gets called.What would be the best design pattern for it. Thanks

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        The question doesn't make sense. Presumably "a,b,c" are in fact different classes and not in fact different instances. And in the context of programming (not data) there is no point in having a "primary key". And it is probably a design flaw if you do in fact have 10 different classes and you intend to store then in a single table (for which the 'primary key' would in fact be a type value and not a 'primary key'.) You do not "save" classes. Instead you save data. Design patterns apply to programming designs. The term does not apply to data. Nothing in your description as defines that there is any data at all to save with the "button". But if you meant the following 1. You do in fact have 10 different classes where the data is the same (guaranteed) but the behavior is different. 2. You have an attribute that differentiates each class. What you are referring to has the "primary key". I will refer to it however as the 'type'. 3. The button has a state of either on or off. The the persistent storage object (database table) would consist of three columns: Id, Type and ButtonState. The 'Id' exists because, presumably, you are going to want to store more that one instance of a, and more than one instance of b, etc.

        1 Reply Last reply
        0
        • L Lost User

          You'll need a "class id and instance key" for the "10 different classes" if you want to relate them to a single source of "Charge classes". (bi-directional parent-child relation).

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          A Offline
          A Offline
          as almas
          wrote on last edited by
          #4

          Suppose you have two classes:
          Class1: public class Class1 { //Your code above }
          Class2: public class Class2 { }
          You can use Class2 in different ways:
          Class Field: public class Class1{ private Class2 class2 = new Class2()https://ssafu.com/ }

          1 Reply Last reply
          0
          • L Lost User

            You'll need a "class id and instance key" for the "10 different classes" if you want to relate them to a single source of "Charge classes". (bi-directional parent-child relation).

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            R Offline
            R Offline
            Racy jordan
            wrote on last edited by
            #5

            In short, the number of . class files created will be equal to the number of classes in the code. We can create as many classes as we want but writing many classes in a single file is not recommended as it makes code difficult to read rather we can create a single file for every class.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups