(not-so-mini) mini project.

Sorry about the late post, I forgot about this bit whilst working on the wee project. Speaking of which, is still in the works, I don’t know for sure where my problem is, but I am willing to bet it has something to do with the State pattern, cause I ahve yet to successfully implement it in either my big or little project. I continue to get null pointer exceptions.

The process was rather straight forward for me in the beginning. I started how I always start a program, I wrote it out in simplified UML. I was able to get 75% of the work done this way, as implementing  the Strat,Observer, and Decorator patterns are rather straight forward once you know what to do. My original mini project had about 23 classes, and this was due mainly to a couple factors:

1) I thought it was a good idea to show the patterns work on several different classes

2)My version of small is apparentally big, which as a student is reassuring

3)this thing I thought was kinda clever required alot of state’s to really show it’s inner beauty, problem is, I ain’t as clever as I thought, I still can’t make the state pattern work for some reason, and the idea happened halfway through the process, so I didn’t write it down and fit it in, I just tried hacking it in, which never seems to work for me.

The State,Observer, and Decorator pattern all function just fine in my program, but the state continues to elude me, and the frustrating part is I am not at all sure how, because it looks like it should all work fine (of course if something looked wrong I would have fixed it, so the previous point is kinda moot) Mainly, it’s null pointer exceptions, and I think I understand now that what I am having an issue with is the fact that I don’t exactly know what a state is, and thus am probably not initializing them correctly. I am going to seek help tomorrow, because I am getting really desparate here, cause I can’t afford to fall behind.

Outside writing it out, The creation went something like this. I don’t know if this is the easiest approach, but this is how I’ve always done my programming (which isn’t saying much, I haven’t got a ton of programming xp under my belt) but after getting the UML figured out, I generally know what classes I need to create, and how to connect them, so that was my next step. I created the Strat first, laying out the base class, sub classes, Behavior interface, and behavior implementers, and then created the reference variable inside the base class. Next, I worked with the observer pattern, which was much nicer this time around since I used Java API, it was actually extremely simple, and I think I am going to go ahead and try and remove my interface style observer pattern from my main project and reimplement the API version. Finally, I went ahead and made the Decorator pattern, which was not difficult at all. Once it was in place I got to thinking. It’s kinda lame that the decorations have to be hard coded in the driver, and you can’t dynamically create wrappers. So my first idea that didn’t work was to make a method that took in a subject to be wrapped and a wrapper. Then wrote out an algorithm that would return a wrapped object. It went kind like

public void Decorate(Object toBeWrapped, DecObject     Wrapper){

toBeWrapped = new Wrapper(toBeWrapped);

}

but it didn’t work cause of something with the Wrapper. So I thought, “well, lets have the decorations depend on the state then” And I was going to have wrappers change with the state. Which once I had created the states, I realized that I would need alot of references for each one. So, I created a parent class taht would hold the reference variables, and the states would exend this class. I thought it was nifty. Then I would write a method Progression()  that was specific to each state, and as each state passed it would wrap the different characters in different decorations. But I ended up getting an infinte loop of null pointers, then just a straight up null pointer, then kevin telling me to knock it off and just implement the patters. Which I did, cept for the state, which I need help on, cause I am lost.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.