• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a method to return different string depending on situation

 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far there is a video class that contains a method to check in a movie


I'm creating a class customer that will keep count of videos and what videos are checked in and out
that belong to the customer. So I want the result to decrement/increment the video from the store
while simultaneously increment/decrement the video to the customers account. My question is
can I use the same method videoCheckIn from the video class and somehow display a different message
when the video is not available such as "this video is not on the customer's account" or will I have
to create a whole new method in my customer class almost exactly the same with a different s.o.p ("string")?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could pass what ever message you want to be displayed as a method parameter.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I'll have to look up the syntax on how to write the code for that but I think I understand what your saying! This brings me to another question, if I use this same method from the video class will it keep a list of the movies the customer is checking out just
like it does for keeping track of the video's in the store from the infile data file and apply it to this customer's account with XXX id number?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasnt able to completely grasp your implementation, but have managed to let you know how to go about with your requirement. From what I see- I was thinking if the code structure would be as follows:


The above code is a very basic structure I could think of. You can improvise it. I am thinking if there's some flaw with the design in terms of- loose coupling and high cohesion.
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have, If I understand what your saying I would have to manipulate my videoCheckOut method to be able to print "The customer does not have this video" if the video is not in the customers list. On the other side of things the same method used for the list of video's in the store videoList.videoCheckout would come out with a message saying "The store does not have this video."

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic