Where should function reside?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anane
    New Member
    • Dec 2007
    • 9

    Where should function reside?

    In my application I have 3 classes.

    1. class A
    2. class B
    3. class C

    Application controller (having main function) has the object of class A, class A has object of class B and class B has objects of class C.

    Application Flow:
    1. Application reads some inputs.
    2. Application does some calculations.
    3. Stores generated data into excel file.

    My question is:
    Functionality of setting of data members of the class should be in main function or in their respective parent classes?

    Means: function which sets data members of class C , should reside in Class B or it should be in class "Applicatio n controller"?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Anane
    In my application I have 3 classes.

    1. class A
    2. class B
    3. class C

    Application controller (having main function) has the object of class A, class A has object of class B and class B has objects of class C.

    Application Flow:
    1. Application reads some inputs.
    2. Application does some calculations.
    3. Stores generated data into excel file.

    My question is:
    Functionality of setting of data members of the class should be in main function or in their respective parent classes?

    Means: function which sets data members of class C , should reside in Class B or it should be in class "Applicatio n controller"?
    What do classes A, B and C do? You don't write down class names before you decide what the classes are supposed to do. Rather the application logic decides which classes are needed. The methods are simply actions which objects(created from your classes) can perform. So as an example(a lame one) if you decide that you need an Input class, the action readInput would obviously be a method in the Input class.

    Comment

    • hirak1984
      Contributor
      • Jan 2007
      • 316

      #3
      Originally posted by Anane
      In my application I have 3 classes.

      1. class A
      2. class B
      3. class C

      Application controller (having main function) has the object of class A, class A has object of class B and class B has objects of class C.

      Application Flow:
      1. Application reads some inputs.
      2. Application does some calculations.
      3. Stores generated data into excel file.

      My question is:
      Functionality of setting of data members of the class should be in main function or in their respective parent classes?

      Means: function which sets data members of class C , should reside in Class B or it should be in class "Applicatio n controller"?
      according to my understanding of your problem,
      neither should the business logic stay in the "main", nor in the classes (A,B,C whatever).
      it should stay in some private method, which the main will call to execute the job.
      but please post details of your application, for better understanding.

      Comment

      • Anane
        New Member
        • Dec 2007
        • 9

        #4
        Originally posted by hirak1984
        according to my understanding of your problem,
        neither should the business logic stay in the "main", nor in the classes (A,B,C whatever).
        it should stay in some private method, which the main will call to execute the job.
        but please post details of your application, for better understanding.


        Detailed explanation:
        take example of vehicle engine: Engine(class A) has cylinders(Class B). Cylinder has pistons(Class C). each class have got their own data members.
        Like for class A :1. engine no. 2. engine material 3. engine size. etc
        Class B : 1. cylinder diameter 2. cylinder thicknes 3. cylinder height
        Class C : 1. piston diameter. 2. piston material 3. piston thickness

        my question is : function assigning values to data members should reside where? in "applicatio n controller class" or in respective classes that is function which set data menbers of class piston should reside in class "Class piston" ?

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by Anane
          Detailed explanation:
          take example of vehicle engine: Engine(class A) has cylinders(Class B). Cylinder has pistons(Class C). each class have got their own data members.
          Like for class A :1. engine no. 2. engine material 3. engine size. etc
          Class B : 1. cylinder diameter 2. cylinder thicknes 3. cylinder height
          Class C : 1. piston diameter. 2. piston material 3. piston thickness

          my question is : function assigning values to data members should reside where? in "applicatio n controller class" or in respective classes that is function which set data menbers of class piston should reside in class "Class piston" ?
          Normally you have them in the class whose members they are setting.

          Comment

          • hirak1984
            Contributor
            • Jan 2007
            • 316

            #6
            Originally posted by Anane

            my question is : function assigning values to data members should reside where? in "applicatio n controller class" or in respective classes that is function which set data menbers of class piston should reside in class "Class piston" ?
            Normally the set data members of class piston should reside in class piston.
            and u will call the set...() of the piston class from your main to set the values.
            hope that is clear.
            god bless

            Comment

            Working...