Classes and Global Data

OK, I've been battling how to do this with my test code and now it comes back to "bite" me in my new project.
In regular C, you just create your structures, fill them with data, and then your subroutines have full access to the global data.
With Objective-C you envelop certain data inside other objects. I got that. In fact, that's where I've gotten "stuck". Let me elaborate.
I have a the following classes:
Class (number of instances expected) description of class
Scenes (1) tables containing dictionaries of scenes and scene components
Pieces (1) tables containing images, type specs, etc. of game pieces
Blocks (1) tables with definitions, specs of movable game pieces
MainView (1) main application view, contains methods to draw the main gameboard
BlockView (n) view for the block and data needed to manipulate it by the main game logic
MainViewController (1) main controller for game screen
Ok, since MainView manages the game window it's init methods also call the init methods to instantiate the one instance of Scenes and Pieces which are needed to be setup in order for MainView to draw the currentScene using the UIImage figures for each of the pieces. So, it saves a pointer to the Scenes and Pieces instances. MainViewController can access those since it sets up MainView and has a pointer to it. MainViewController is currently where I had planned on firing up the BlockView subviews, one for each movable game blocks.
The problem comes with BlockView which has the logic to setup the additional data for each block type, but does not have a pointer to the instances of Scenes or Pieces which contain the current scene info and the UIImage dictionary to use for drawing the actual images on the screen. How can it get a pointer to the appropriate classes?
Since BlockView is invoked by MainViewController as it sets up the pieces, I could pass the pointer as part of the init method, but that seems like the WRONG place. Shouldn't I be able to put some block of pointers someplace where all objects can query to get the data needed (keeping it encapsulated within some master gameSettings object).
Actually that's part of where I'm going with this. I want to have a settings object which knows what scene is current, what block set (images) is in use (so I can have different images for each piece depending on which set is selected), and the saved state information needed to continue where I left off. (This part is mostly a serialization of the Blocks instances which contain both the initial and current locations on the screen, and the current background tableau which shows a more-or-less static background for each scene).
Instead of one object, right now I've separated the types of information by 3 classes, but everything needs access to two of those classes in order to fully function. I think I have that part under control. What I don't have is the BlockView instances and the GameLogic methods having access to the Scenes and Pieces data unless I pass a pointer to them during initialization.
Is that what I'm supposed to do?
Or is there a better way?
Lastly, my game logic is really a set of methods which act on ONE specific piece to move it, but then that movable piece (one of the instances of BlockView) is able to push other pieces as it moves. Additional methods will handle the pushing of the other instances of BlockView around until a solution is completed for the scene. That part, I think I've gotten OK, as the game logic will be Built into the Blocks or BlockView classes. (That's the part I will have to figure out).
I'm adding this to my query, so you know my intention, and whether I'm on the right track. So far my Blocks class only contains definitions used by BlockView, and no instance variables or methods yet. If all the logic can be put into the BlockView methods, I can probably throw Blocks away.
So, do I add a pointer to my init method...
- (id)initWithString:(NSString*)myType atPoint:(CGPoint)point
becomes
- (id)initWithString:(NSString*)myType atPoint:(CGPoint)point inScene:(Scene)scene ofSet:(Pieces)pieceSet
If that is what it takes, I can do it. It just seems there ought to be a better way.
Of course, I could abstract those last pointers to only provide the pieces needed for that one instantiation of a BlockView, as I have with 'myType' and 'point' by supplying only the 'pieceSet' to init, but then the game logic will need to have access to the 'scene' to know whether a given block is allowed to move to a given position. This is where I get confused as far as what information to pass to a class, since I know other methods invoked by touches will cause the blocks (in BlockView instances) to move around on the screen displayed by MainView.
Actually MainView will be detecting the touches and moving the instances of BlockView, so maybe the game logic SHOULD be in MainView instead. I just figured that to encapsulate it as methods that operate on the movable pieces, the methods should be in BlockView, and called by the touch detection routines in MainView.
Comments please. And don't say, you can do it either way... one way or the other, or yet a third way I don't fully comprehend (such as another viewController) should contain the logic. I think the logic is part of the model and not the view, but in this case, it affects the view based on the background squares and what happens to each block as it is moved or pushed "into" one of those squares.
Thanks in advance. I realize this may be a complicated question, but I think it is a fairly BASIC question, and my lack of Objective-C experience is showing.
To tie the question up a little better, I'm not expecting to have all objects have complete access to lots of global data. What I'm looking for is a place to put a pointer to each of my classes which are only ever instantiated once, and have that pointer be findable by any other class that can then query the appropriate class instance to retrieve the data. Right now, I have one and only one place holding these pointers, and am passing them to the objects/classes which need access to the data in those Scene and Pieces classes when they need them.
If that is the way I'm supposed to do it, then I'm on the right track, even if it means deciding which classes are allowed to hold and pass the appropriate object pointers to other objects.

etresoft wrote:
I think you are missing an important piece - the "model" - from the MVC architecture - Model, View, Controller.
Your "business logic" is composed of your Scenes, Pieces, and Blocks. That is your model. Your view shouldn't really know anything about that. Your controller understands both your model and your view and it puts the two together to draw things. You want to be able to swap our your GUI view for a text view, if you wanted to. Chess, for example, can be played in a GUI or from a text console. A more modern example is a multiplayer game. It has to function across a network so its model has to be projected to the local display as well as sent across the network.
Yes, I am still fighting with understanding the implementation of some concepts.
What I think I am wanting to do, is similar to what Apple has done with the file manager or notification centers, and be able to request information from my model as needed.
For example, my view doesn't care about the specifics of the scenes or pieces, yet my view wants to be able to display the name of the current scene or display the correct image for a piece. Right now, it keeps an instance pointer to my "singleton" Scene object, and using the scene index, gets the current name. To display images, it gets those from the Pieces singleton's image dictionary, and again keeps a pointer to do that.
What I would rather do is be able to get that pointer for the views that need it without having to copy it, or have back pointers to the superview which holds a copy of those pointers. My BlockView class layers the active pieces over the MainView which holds the playing board. To access things, my code looks like:MainView* mainView = (MainView*) self.superview;
NSString* key = [mainView.myScene.sceneKeys objectAtIndex:mainView.currentSceneIndex];
NSString* pieceName = [[mainView.myScene.scenes objectForkey:key] pieceAtLocation:loc];
UIImage* image = [mainView.myPieces.images objectForkey:pieceName];
Oh, and this isn't actual code. It is a contrived example. I have since made it more efficient.
What I think would be more appropriate would be something like this:
NSString* pieceName = [[Scenes CurrentScene] pieceAtLocation:loc];
UIImage* image = [[Pieces PieceImages] objectForkey:pieceName];
or even
UIImage* image = [[Pieces PieceImages] objectForKey:[[Scenes CurrentScene] pieceAtLocation:loc]];
When I attempt to create class methods to access data in my "singleton", I get lots of warnings about accessing instance data in a class method. So, instead I made everything an instance method, but that requires keeping a pointer to the instance available somewhere.
I have been able to recode some of the instance methods which manipulate derived strings from the instance data into class methods, but not the data read in from the plist data files.
What I'm missing is how to get the current "singleton" instance from the class, and then use that as the instance pointer, i.e. in the examples above, I guess that pieceAtLocation: would be an instance method, but CurrentScene and PieceImages would be class methods that return an instance pointer to the appropriate dictionaries. How to implement that correctly is where I'm still sketchy.
Isn't that how Apple has defined DefaultNotificationCenter or DefaultFileManager?
I've looked at some singleton code, and am not sure how it helps me get this done, so an example would definitely help.

Similar Messages

  • Differnace b/w SID and Global data base name

    please tell me what is differance b/w SID and global data base name.

    Hi,
    Oracle System Identifier (SID)
    A name that identifies a specific instance of a running pre-release 8.1 Oracle database. For any database, there is at least one instance referencing the database.
    For pre-release 8.1 databases, SID is used to identify the database. The SID is included in the connect descriptor of a tnsnames.ora file and in the definition of the listener in the listener.ora file.
    http://download-uk.oracle.com/docs/cd/B19306_01/network.102/b14213/glossary.htm#i433004
    Global database name
    The full name of the database which uniquely identifies it from any other database. The global database name is of the form "database_name.database_domain," for example, sales.us.acme.com.
    The database name portion, sales, is a simple name you wish to call your database. The database domain portion, us.acme.com, specifies the database domain in which the database is located, making the global database name unique. When possible, Oracle Corporation recommends that your database domain mirror the network domain.
    The global database name is the default service name of the database, as specified by the SERVICE_NAMES parameter in the initialization parameter file.
    http://download-uk.oracle.com/docs/cd/B19306_01/network.102/b14213/glossary.htm#i435858
    Adith

  • Transfer class and characteristics data from 3.1i system to ECC 6.0 system

    I have to develop a program to transfer all the classes and characteristics( tcode cl01 and ct04)  in a 3.1i system to an ECC 6.0 system.
    I initially planned to use FMs BAPI_CLASS_GETDETAIL to read from 3.1i and BAPI_CLASS_CREATE to load in ECC 6.0.
    But then I realized that BAPI_CLASS_GETDETAIL does not exist in 3.1i system.
    Could anyone please tell me how to transfer the class and characteristics data from 3.1i to ECC 6.0. What approach and FMs are to be used.
    Thanks,
    Karthik

    Thanks for the reply Madhu.
    We are trying the ALE way, using BD91 and BD92. This way seems to be easier as there is no need to extract data to files.
    IDoc is successfuly sent from the 3.1i system but we are not able to see it in ECC 6.0 system.
    We are checking up the settings.
    Would be very useful if you can provide some more details about the settings to be done.
    Thanks,
    Karthik

  • Smart forms and global data

    are parameters defined in global data in smart forms unavailable in form routines to be used
    I am working on lbbil_invoice std smart form for invoices and trying to use gs_it_gen type lbbil_it_gen that is been defined in global data. Will I have to define another wa of the same type in my sub routine ?

    I am working on a smart form right now
    I define in global data
    gv_fabrictext type char64
    gv_fabriccode type mara-j3afcc
    then in my form routines i create a sub routine
    FORM fcc_values USING gv_fabrictext.
    and making computations to calculate gv_fabrictext
    then i use a program code and call perform fcc_values using gv_fabrictext with gv_fabrictext as input and output parameters
    Is this correct? Why do I have to define gv_fabriccode type mara-j3afcc  in the form routine even though its been defined in global data

  • Equipment search based on Class and Characteristic data

    Hello Experts,
    We are looking for some inputs on how to get index created on Class and Characterstics for Equipments.
    We are using Embedded Search , TREX Version 7.10.44.00,  Changelist 323327 (710_REL),   InstallationType ESH along with ECC 6.0/Ehp4.
    We can't see any standard template available in our cockpit(ESH_COCKPIT) for Class and Characteristic but we can see a template on Equipment(EQUI).
    We have the following software components available : EA-HRGXX, ESH_COMMON_OBJECTS and SAP_APPL however class and characteristic are missing.
    We tried to import it but unavailable in the import queue. Hence it seems we need to create it manually.
    Question:
    Is it available in some patch or something from where we can import it? We assume these should be definitely available somewhere since these are standards templates.
    From where we can get the technical details if we want to create these manually?
    How to configure the index to get the relevant field data from ECC-->TREX for these new indexes(Class/Characteristic) created?
    What extra coding required to do this? Where we can find the details on how to program and run this?
    Any other related info around this will be really helpful.
    Many Thanks
    Sanjay

    hi,
    the standard templates are only delivered with EHP5 and NW 7.2 as part of the standard delivery.
    cheers,
    Om

  • Abstract classes and recursive data

    I am trying to create my own mini "RPG" game and right now I'm starting off with the basics; potions for players. However, when I attempt to define my classes I get the following error when compiling compound.java
    *\compound.java:8: cannot find symbol*
    symbol  : constructor mixture()
    location: class mixture
    *^*
    *1 error*
    Basically a MIXTURE can be one of three things:
    Water
    A Potion
    Compound (two mixtures)
    Here are my two classes:
    abstract class mixture
         private water h2O = null;
         private potion potn = null;
         private compound cmpnd = null;
         mixture(water w)
              this.h2O = w;
         mixture(potion p)
              this.potn = p;
         mixture(mixture m1, mixture m2)
              this.cmpnd = new compound(m1, m2);
         public void getContents()
              if(this.h2O != null) { getWater(); }
              if(this.potn != null) { getPotion(); }
              if(this.cmpnd != null) { getCompound(); }     
         public water getWater() { return this.h2O; }
         public potion getPotion() { return this.potn; }
         public compound getCompound() { return this.cmpnd; }
    public class compound extends mixture
         // A compound consists of two mixtures
         private mixture mix1;
         private mixture mix2;
         compound(mixture m1, mixture m2)
              this.mix1 = m1;
              this.mix2 = m2;
         public mixture getMix1() { return this.mix1; }
         public mixture getMix2() { return this.mix2; }
    }Thank you for any help you can provide!
    Edited by: blacksaibot on Nov 16, 2008 10:03 AM

    The error message is telling you exactly what's wrong. As per the rules below, you're trying to call a constructor on you mixture class (should be Mixture, by the way--classes start with uppercase by convention) which doesn't exist.
    Also, I strongly recommend you get a firm grounding in the basics before attempting anything with even a fraction of the complexity of an RPG. You're just setting yourself up for frustration otherwise.
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.
    Edited by: jverd on Nov 16, 2008 10:25 AM

  • Document Classes and other Questions

    Basically, i am working on an application that will eventually be deployed to the desktop as an AIR application.
    I am wanting to create an Analogue clock and Digital clock with a button that toggles the display between either one when pressed. As well as this, i will be wanting to display the Date below, i am having a number of issues however.
    I have the code sorted for three of the four components, i have not attempted to figure out the button thus far as i would be more than happy to have the digital clock, analogue clock and date all being displayed on a drag and drop desktop application first. When i say i have it sorted, i have a fully working analogue clock which i have managed to display on the desktop through air on its lonesome, however, i did not include the drag and drop function. For the digital clock and date components i am not sure how to configure them into document classes. The main issue i am having is i do not know if you can reference a dynamic text box within a movie clip to a document class.
    This is the code to show the date
    [code]{
    var currentTime:Date = new Date();
    var month:Array = new Array("January","February","March","April","May","June","July","August","September","Octo ber","November","December");
    var dayOfWeek:Array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    date_text.text = dayOfWeek[currentTime.getDay()] + " " + currentTime.getDate() + " " + month[currentTime.getMonth()] + " " + currentTime.getFullYear();
    [/code]
    I have put the actionscript frame inside the movie clip file, and i have given both the movie clip, and the dynamic text box within the movie clip the instance name "date_text".
    Basically, i am just struggling in how to put this code into a working document class, since the digital clock and date functions are both, some what similar, i feel the solution to one will more than likely lead to me discovering the solution for the other.
    The other problem i am having, i do not know how i will display all of the components on one air application. I am assuming, that you create one other document class file which links the other four together? i have tried to do this by just linking a new FLA file with the analogue clock, but it does not work. The code for that is below.
    [code]package
              import flash.events.Event;
              import flash.display.MovieClip;
              public class time1 extends MovieClip
                        public var now:Date;
                        public function time1()
                                  // Update screen every frame
                                  addEventListener(Event.ENTER_FRAME,enterFrameHandler);
                        // Event Handling:
                        function enterFrameHandler(event:Event):void
                                  now = new Date();
                                  // Rotate clock hands
                                  hourHand_mc.rotation = now.getHours()*30+(now.getMinutes()/2);
                                  minuteHand_mc.rotation = now.getMinutes()*6+(now.getSeconds()/10);
                                  secondHand_mc.rotation = now.getSeconds()*6;
    [/code]
    That is the original clock document class (3 Movie clips for the moving hands, and the clock face is a graphic, which i may have to reference somehow below)?
    [code]package
              import flash.display.MovieClip;
              public class main extends MovieClip
                        public var hourHand_mc:time1;
                        public var minuteHand_mc:time1;
                        public var secondHand_mc:time1;
                        public function main()
                                  hourHand_mc = new SecondHand();
                                  addChild(mySecondHand);
                                  hourHand_mc.x = 75;
                                  hourHand_mc.y = 75;
                                  minuteHand_mc = new SecondHand();
                                  addChild(mySecondHand);
                                  minuteHand_mc.x = 75;
                                  minuteHand_mc.y = 75;
                                  secondHand_mc = new SecondHand();
                                  addChild(mySecondHand);
                                  secondHand.x = 75;
                                  secondHand.y = 75;
    }[/code]
    This is my attempt at creating the main document class in a seperate FLA file to attempt to load the analogue clock, and later on the Digital Clock, Date Function and Toggle Display button in the same AIR application.
    Any help on this is much appreciated, i have been reading up a lot on it through tutorials and the like, but i can't seem to fully grasp it.

    why do you have code in a movieclip?
    if you want to follow best practice and use a document class you should remove almost all code from timelines.  the only timeline code that might be reasonably used would be a stop() on the first frame of multiframe movieclips.
    so, you should have a document class.  that could contain all your code but it would be better to just have your document class create your 2 clocks and date objects and possibly manage toggling between the two clocks.  you could have a separate class the tracks the time and date and that class is used by your two clock classes and your date class.

  • What is diff between Global and 2nd Part Global Data in Transformation

    Hi,
    Does anyone know what the difference between declaring global data in the 'begin of global' data area in the class declaration and the 'begin of 2nd part global' area outside the class...endclass in ABAP routines in a transformation??
    Thanks,
    Mark

    Hello,
    In the first global part you can write your declaration or code you want to be able to reach globally
    in the tranformation. The 2nd global part will be used for those transformations which are migrated from an update or transfer rule. Routines used there will be automaticaly generated into the 2nd global part.
    Best Regards,
    Paula Csete

  • Access global data of report in global class methods?

    Hi all,
    I have defined one global class in SE24 and i am using methods of this class in report program.
    Can i access global data of my report program in class methods directly without declaring it as IMPORT
    parameter?
    Thanks,
    Apita

    Hi,
    Well, now you did confuse me: first you asked about using global data of a report program in global class (created in SE24), and the answer is: no, you can't directly access the global data of another program in a method of global class (yes, you should pass them via importing parameters), and you shouldn't even consider using indirect means of doing so via special form of ASSIGN statement reserved for internal use by SAP. The ASSIGN will not work if someone reuses the global class elsewhere in the system without loading your report. Don't ever program such atrocious dependencies in global class...
    And now you ask about the use "in method implementation in report program"..? Just to be sure - you can't program the implementation of a global class method in a report program.
    You can program a local class inheriting from a global class and redefine/re-implement methods of such global super-class in a report program. Global data of report program, including the selection screen, would be directly accessible to such local class. It would still not be a good idea to use this access:
    Conversely, within an encapsulated unit, that is, within a class, you should avoid accessing more global data directly. Within methods, you should generally modify attributes of the class only. Write access to global data outside the class is not recommended. Accessing data in this way should only be done using specially marked methods, if at all. The use of methods of a class should not evoke any side effects outside the class itself.
    cheers
    Jānis
    Message was edited by: Jānis B

  • Data class and Delivery class in ABAP Dictionary

    Hi all,
    I want to know the exact information about Data class and Delivery class in ABAP Dictionary
    Moderator message : Search for available information. Thread locked.
    Edited by: Vinod Kumar on Aug 3, 2011 1:35 PM

    As your name Suggests, there were exactly 21 rajapandian already who wanted exact information about  Data class and Delivery class. Fortunately some has found the information by own and some were dumped by SAP Police.
    Cheers
    Amit

  • Can I create a class and package for my inframe AS and access it global

    Ls,
    I made an app using only inframe actionscript in a .fla;
    transfrerring variables from frame 1 to frame 2 is unreliable.
    Some sources say the persist over frames but i found that not to be reliable.
    Arrays seem to be filled with the right values. Normal int vars declared in frame 1 fail some time.
    You should have used classes i hear you say,  and right you are.
    But I didnt.
    Now im using either reloading, re-initing and/or the sharedobject.
    Anyhoe..
    Question:
    If I declare a class for my main .fla file.,
    then declare, instantiate and load the globals i want in this main class,
    will I be able to acces these variables in my main .fla timeline script?
    If so, I could slowely reconstruct my .fla into smaller objects/classes and make it a real app.
    Just starting from scratch is. welll..i dont even want to think about that.
    Highest regards,
    Mac

    Yes! I got it to run as Mobile project.
    Now, how to test on my mobile thru USB.
    I'm more/only used to working from FLASH CS5.5
    Although I like the builder, it feels really flexible, it also seems more work(yeah still lazy).
    Is there an advantage to using the builder over Flash CS?
    Thank you.. again...again
    Mac

  • HELP, date class and parsing input

    I have reviewed many posts in these forums and have found that detail gets the best results so I apologize in advance if this is detailed. I am taking a Java class and am not doing so hot. The last time I programmed was in 1998 and that was Ada, I very soon moved to Networking. I guess those that can't program become networkers, I don't know, but I am frustrated here.
    Any how I am trying to write a rather simple program, but it is the manipulation of the date I am having difficulty with. Here are the requirements:
    Overall Requirements
    Create a class named Date that stores date values and prints out the date in either a pure numeric format or a name and number format (see sample session for format details).
    Date.java class file
    ? Date objects should store the date in two int instance variables ─ day and month, and it should include the String instance variable, error, initialized with null.
    Implement a 1-parameter Date constructor that receives a dateStr string parameter and performs complete error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error checking. That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value, using an appropriate concatenation of a string constant, input substring, and/or API exception message.
    Constructors use the same exception handling rules as methods: In a try block, include the parsing of the month and day substrings and other error-checking logic that will not work if parsing fails.
    ? Take into account the actual number of days in each month, but assume that there are always 28 days in February.
    ? To extract day and month numbers from the given date string, use String?s indexOf method to find the location of the slash character, and String?s substring method to extract month and day substrings from the input string.
    ? Include a method for printing the date with a numeric format. Use the zero-pad flag in a printf method call to get exactly two digits for each month and day.
    ? Include a method for printing the date with an alphabetic format.
    Include a getError method which returns the value of the error instance variable.
    DateDriver.java class file : In your driver class, include a loop that repeatedly:
    ? Asks the user to enter a date or ?q? to quit. ? If the entry is not ?q?, instantiate a Date object.
    ? If the error variable is null: o Print the date using numeric format.o Print the date using alphabetic format. Otherwise, print the value of the error variable.
    I want to figure this out on my own as much as possible but have until tomorrow night to do so..............I need to understand how I can use Strings indexOf to parse the dateStr so I can locate the /. I see I can use it to find the position of a specified character, but I am not sure of the syntax I need to use. But then once I find the / I need to use the String's substring method to extract month and day. I think I might be able to get that, if I can get the / figured out.
    The below is what I have in my Class and my Driver so far:
    *DateDriver.java (driver program)
    * Christine Miller-Lane
    *Overall Requirements
    *Create a class named Date that stores date values and prints out the date in either a pure numeric
    format or a name and number
    *format (see sample session for format details).
    *DateDriver.java class file
    *In your driver class,
    *????????? If the error variable is null:
    *     ◦     Otherwise, print the value of the error variable.
    import java.util.*;
    public class DateDriver
    Date datevalue;
    public static void main(String[] args)
         Scanner stdIn = new Scanner(System.in);
         while (!xStr.equalsIgnoreCase("q"))
         try
              System.out.println("Enter a date in the form mm/dd ("q" to quit): ";
              value = stdIn.nextLine();
              datevalue = new Date(value);                                                        //instaniate the date object
              System.out.println //print date in numeric format
              System.out.println //print date in alphabetic format
              break;
              catch
              System.out.println("print value of error variable.");
              stdIn.next(); // Invalid input is still in the buffer so flush it.
         } //endloop
         }//end main
    } //end class?
    * Date.java
    * Christine Miller-Lane
    *Overall Requirements
    *Create a class named Date that stores date values and prints out the date in either a pure numeric format or a name
    *and number format (see sample session for format details).
    *Date.java class file
    *????????? Date objects should store the date in two int instance variables ─ day and month, and it should include
    *the String instance variable, error, initialized with null.
    *     ?     Implement a 1-parameter Date constructor that receives a dateStr string parameter and performs complete
    *     error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error
    *     checking. That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the
    *     Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance
    *     variable to a non-null string value, using an appropriate concatenation of a string constant, input substring,
    *     and/or API exception message.?
    *     ?     Constructors use the same exception handling rules as methods: In a try block, include the parsing of the
    *     month and day substrings and other error-checking logic that will not work if parsing fails.
    *????????? Take into account the actual number of days in each month, but assume that there are always 28 days in February.
    *????????? To extract day and month numbers from the given date string, use String?s indexOf method to find the
    *location of the slash character, and String?s substring method to extract month and day substrings from the input string.
    import java.util.*;
    public class Date
         Scanner stdIn = new Scanner(System.in);
         boolean valid = false
         int day;
         int month;
         String error = null;
         String dayStr;
         String monthStr;
         String dateStr;
         public Date(String dateStr)
    // Look for the slash and set appropriate error if one isn't found. use String?s indexOf method to find the
    //location of the slash character and String?s substring method to extract month and day substrings from the input string.
    // Convert month portion to integer. Catch exceptions and set appropriate error if there are any.
    Integer.parseInt(dateStr);
    // Validate month is in range and set appropriate error if it isn't.
    // Convert day portion to integer. Catch exceptions and set appropriate error if there are any.
    // Validate day is in range based on the month (different days per month) and set appropriate error if it isn't.
    //public void printDate()      //Include a method for printing the date with a numeric format. Use the zero-pad flag in a printf method
                                       //call to get exactly two digits for each month and day.
    //{                                   //Include a method for printing the date with an alphabetic format.      
    //     } // end print report
    //     public getError()
                                  //Include a getError method which returns the value of the error instance variable.
    }//end class Date
    Here is sample out put needed::::::::
    Sample Session:
    Enter a date in the form mm/dd ("q" to quit): 5/2
    05/02
    May 2
    Enter a date in the form mm/dd ("q" to quit): 05/02
    05/02
    May 2
    Enter a date in the form mm/dd ("q" to quit): 52
    Invalid date format ? 52
    Enter a date in the form mm/dd ("q" to quit): 5.0/2
    Invalid format - For input string: "5.0"
    Enter a date in the form mm/dd ("q" to quit): 13/2
    Invalid month ? 13
    Enter a date in the form mm/dd ("q" to quit): 2/x
    Invalid format - For input string: "x"
    Enter a date in the form mm/dd ("q" to quit): 2/30
    Invalid day ? 30
    Enter a date in the form mm/dd ("q" to quit): 2/28
    02/28
    February 28
    Enter a date in the form mm/dd ("q" to quit): q
    I am trying to attack this ONE STEP at a time, even though I only have until Sunday at midnight. I will leave this post and get some rest, then attack it again in the morning.
    Edited by: stillTrying on Jul 12, 2008 8:33 PM

    Christine,
    You'r doing well so far... I like your "top down" approach. Rough out the classes, define ALL the methods, especially the public one... but just sketch out the requirements and/or implementation with a few comments. You'll do well.
    (IMHO) The specified design is pretty crappy, especially the Exception handling
    [The Constructor] performs complete error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error checking. That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value, using an appropriate concatenation of a string constant, input substring, and/or API exception message.Please allow me to shred this hubris piece by piece.
    [The Constructor] performs complete error checking on the given dateStr value. The Date constructor is the entity that?s responsible for date error checking.Umm... Well I suppose it could... but NO, the constructor should delegate such "complex validation" to a dedicated validate (or maybe isValid) method... which might even be made publicly available... it's a good design.
    That way, if a Date object is instantiated and if there are no errors, then you?re guaranteed that the Date object holds a legitimate date value. If any kind of error occurs, change the value of the error instance variable to a non-null string value ...Utter Bollocks! When passed an invalid input string the, Date constructor should throw an InvalidDataException (or similar). It should not SILENTLY set some dodgy error errorMessage attribute, which is returned later by a "print" method. We tried that in masm, fortran, ada, basic, c, and pascal for twenty odd years. It sucked eggs. And it STILL sucks eggs. Java has a "proper" try/catch exception handling mechanism. Use it.
    I mean, think it through...
      someDate = get a date from the user // user enters invalid date, so someDate is null and errMsg is set.
      report = generateReport() // takes (for the sake of argument) three hours.
      emailReport(someDate, report) // only to fail at the last hurdle with an InvalidDataException!And anyways... such implementation details are traditionally the implementors choice... ie: it's usually between the programmer and there tech-manager (if they're lucky enough to have one).
    Cheers. Keith.

  • Accessing protected and private data of a class

    Hi friends,
    I have writen a sample code in oops abap but iam facing some problem.
    CLASS MAIN DEFINITION.
        public SECTION.
          DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
          METHODS : PUBLIC.
      ENDCLASS.
      CLASS MAIN IMPLEMENTATION.
         METHOD : PUBLIC.
           WRITE : /5 VAR1.
              VAR1 = 'CHANGED'.
           WRITE : /5 VAR1.
         ENDMETHOD.
      ENDCLASS.
    START-OF-SELECTION.
        DATA :
               O_MAIN TYPE REF TO MAIN.
               CREATE OBJECT O_MAIN.
               CALL METHOD O_MAIN->PUBLIC.
    now its working fine as public methods can be access by all the people where as protected methods can be access by class and subclass so i can inherit the properties of above class and access the protected data.
    where as to access private data , private data can be access by class itself...
    so now how do i access the private data within the class...ie : how do i get the above output when i use a private section instead of public..
                CLASS MAIN DEFINITION.
        private SECTION.
          DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
          METHODS : Private.
      ENDCLASS.
      CLASS MAIN IMPLEMENTATION.
         METHOD : Private.
           WRITE : /5 VAR1.
              VAR1 = 'CHANGED'.
           WRITE : /5 VAR1.
         ENDMETHOD.
      ENDCLASS.
    START-OF-SELECTION.
        DATA :
               O_MAIN TYPE REF TO MAIN.
               CREATE OBJECT O_MAIN.
               CALL METHOD O_MAIN->Private.
    iam getting a error saying you cannot access the private section...
    now private section can be accessed within the class but nt by others...
    to access the private section within the class how should i correct it...
    Regards
    kumar

    HAI,
    Private attributes or methods can be accessed directly by the Object but within the Scope of the Class, but not outside.
    Look at this:
    CLASS MAIN DEFINITION.
    public  SECTION.
    METHODS : Public.
    private SECTION.
    DATA : VAR1(10) TYPE C VALUE 'NEW VALUE'.
    METHODS : Private.
    ENDCLASS. " END of CLASS DEFINITION
    CLASS MAIN IMPLEMENTATION.
    METHOD : Public.
    CALL METHOD Private.
    ENDMETHOD.
    METHOD : Private.
    WRITE : /5 VAR1.
    VAR1 = 'CHANGED'.
    WRITE : /5 VAR1.
    ENDMETHOD.
    ENDCLASS. " END of CLASS IMPLEMENTATION
    START-OF-SELECTION.
    DATA:  O_MAIN TYPE REF TO MAIN.
    CREATE OBJECT O_MAIN.
    CALL METHOD O_MAIN->Public.
    PS: If there is any better alternative solution please share it .
    Best Regards,
    rama

  • Automatic Display of NEW Data in ALV Report using Classes and Methods

    Hi,
    I have developed a ALV Report for displaying data from a set of DB tables using ABAP OO, Classes and Methods. The requirement is to have the report output to be automatically updated with the new entries from the DB table at a regular frequency of tiem may be every two minutes.
    Could anyone please tell me how can this be acheived.
    Thanks and regards,
    Raghavendra Goutham P.

    Yes its possible.
    Take a look at this thread
    Auto refresh of ALV Grid, without user interaction
    Or Rich's blog
    /people/rich.heilman2/blog/2005/10/18/a-look-at-clguitimer-in-46c
    Regards,
    Ravi
    Note : Please mark all the helpful answers

  • Business Object and Global Classes

    is there any link between the Business Objects And Global Classes?
    Sameer

    Hi,
    BO is basicallya reporting tool...
    and now BO will be used for reporting on BW.....
    Check these details BW and BO integration..
    follow the link
    www.scribd.com/doc/7805501/BI-BO-Integration
    http://www.jonerp.com/content/view/170/46/
    Have a look at this:
    http://www.businessobjects.com/products/dataintegration/dataintegrator/sap.asp
    This link has lots of PDF documents between SAP and Business object:
    http://www.businessobjects.com/solutions/sap/default.asp
    Also check:
    http://www.dmreview.com/article_sub.cfm?articleId=2839
    http://searchsap.techtarget.com/general/0,295582,sid21_gci1077480,00.html
    check the foll links.
    http://www.businessobjects.com/solutions/sap/
    http://72.14.235.104/search?q=cache:A5mUGEzyGLUJ:www.businessobjects.com/pdf/solutions/xi_sap_insight.pdfBW%26BUSINESSOBJECTS&hl=en&gl=in&ct=clnk&cd=5
    http://www.buisnessobjects.com/news/press/press2003/cust_sapbw_webseminar.asp
    http://www.buisnessobjects.com/solutions/enterprise_solutions/operational_bi.asp
    http://www.businessobjects.com/products/
    http://help.sap.com/saphelp_erp2005/helpdata/en/a4/1be541f321c717e10000000a155106/frameset.htm
    http://help.sap.com/saphelp_erp2005/helpdata/en/30/8d27425005ca7ee10000000a1550b0/frameset.htm
    regards
    Venkat...
    Edited by: Venkata Narayana Jakkampudi on Dec 30, 2008 12:57 PM

Maybe you are looking for

  • Data flow fails on packed decimal field moving iSeries DB2 data from one iSeries DB to another

    I' trying to use SSIS to move table content from one iSeries DB2 database to another.  I'm using the .Net providers for OleDb\IBM DB2 for i5/OS IBMDA400 OLE DB Provider in the connection managers for the source and destination and the test connection

  • Soap action: in Proxy to soap scenario

    Hi experts, I have a senario of Proxy to webservices. I have imported the wsdl file as external defination, and  have to use two message inside 1) to Insert 2) To Update. Now proxy will run twice a month with same data structure, I have to do insert

  • A file paused during download now appears in Launchpad.  How to remove?

    The Software updater offered 3 items to upgrade.  After it started I paused one of them - I couldn't stop that one altogether.  Now the paused file appears, as paused, in the Launchpad.  I can't find the file-in-progress in download folder or elsewhe

  • Moving item Required field error message

    How do you move the required field error message? for example when a field is left blank and the page submits a error message would populate right under the label and push the item(text box) to the right. Making the form look very ugly. http://i.imgu

  • Stacked Bar graph in ABAP

    Hi, Can I create a Stacked Bar graph using ABAP Function Modules? If yes, can anybody please explain how with any suitable example. I also need different colors in each bar of the graph. Any help would be appreciated. Thanks.