• Post Reply Bookmark Topic Watch Topic
  • New Topic

Helper class common for two different objects.  RSS feed

 
pawan chopra
Ranch Hand
Posts: 419
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an object Book and another object Page. Book has pages. This is the relation ship between these two. Now I have a helper class that adds content in to a Page object. It has 4 methods and each method takes an input parameter of type Page. I need similar functionality for Book object as well. Can any one provide me solution for this?
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pawan chopra wrote:Hi All,

I have an object Book and another object Page. Book has pages. This is the relation ship between these two. Now I have a helper class that adds content in to a Page object. It has 4 methods and each method takes an input parameter of type Page. I need similar functionality for Book object as well. Can any one provide me solution for this?


That's not really how this works. What have you tried? What happened when you tried it? What worked, and what didn't work? How didn't it work? Be specific. Post some runnable code that demonstrates where you're getting stuck. Ask a specific question.

We can't really answer general "how do I do this" type question other than to direct you to the basic tutorials.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need a helper class? Why not add the functionality to the Page class?

As for the solution, I don't think you've given enough information to answer that.
 
pawan chopra
Ranch Hand
Posts: 419
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin Workman wrote:

That's not really how this works. What have you tried? What happened when you tried it? What worked, and what didn't work? How didn't it work? Be specific. Post some runnable code that demonstrates where you're getting stuck. Ask a specific question.

We can't really answer general "how do I do this" type question other than to direct you to the basic tutorials.


Thanks Kevin, But I am asking about the design idea. I think problem can me in analysis as well not only in code. I am able to think only one way to create a separate helper class for Book object similar to Page object.

I have not tried it because it doesn't really matter. I know it's going to work anyhow. but I need a better solution so please if you can think from the design perspective instead of looking for compilation error and logical errors.
 
pawan chopra
Ranch Hand
Posts: 419
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Why do you need a helper class? Why not add the functionality to the Page class?


I have created a helper class because same functionality needs for other objects as well.

Matthew Brown wrote:As for the solution, I don't think you've given enough information to answer that.


Ok I am sorry about that. Let me give you example:



Now I hope its bit clear. I have few methods that are called on XMLFile object under save data. But those methods exists only in child classes not in XMLFile class. So I need to cast it at compile time only. So I have to do something like this in the saveData method



Is there any other solution which is better than this?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!