Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

classes - not too complex i hope?  RSS feed

 
Naf Rash
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 3 classes say class A, class B and class C.
Class A is basically a user-interface and when a button is pressed, class B is invoked. After doing the calculations in class B, class C is invoked. This is basically what my program is doing. However, the program is compiling but then gets stuck- there is no response and no output even after the program becomes unstuck. (I think because an object of classes B and C is in A, and class B has object of class C and C has an object of B!) You could say that class A is the 'main' class atleast that is where the main is.
To complicate things further class C also invokes a method of class B.
My problem is with respect to creating objects of the classes. I know that to create an object of B (because it is invoked in A) the following is done:
B b1 = new B( );
However, for class C where should its object be created? I have tried creating it in A only but then when the methods of class C are invoked in B it is not recognised and the same happens for the method (of class B) which is invoked in class C. Please do try to follow this- I know its complicated but the answer to this probably very simple.
Thanks
 
DreamingWolf Muller
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a reply from a total newbie so please take it with a grain of salt. It seems to me that you built your classes into what would be function subroutines in traditional programming. i.e. your building the procedures then trying to fit the objects into them. Java and other Object Oriented Programming work the opposite. You should try figuring out all the objects you think you'll need, what methods you will need them to perform, then build your classes from there.
A: All your objects defined and the methods (calculations and anything else that needs to be done to them) associated with them.
B: The user interface, the creation of instance variables based on A, and the method calls to A.
C: The class with the Main method to start the ball rolling.
Does that make sense?
DWolf
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!