Refactoring discussion

Post Reply
TubeAlloy
Posts: 141
Joined: Wed Mar 04, 2009 4:07 am
Location: Ireland

Refactoring discussion

Post by TubeAlloy »

I wanted to start a discussion about the changes I'm thinking of making while refactoring. It will help stop me wasting a lot of time if people don't like a change and could also save me a lot of time if I miss a major problem due to being unfamiliar with the code as a whole.

I didn't like the fact that the time at which we know the server ip, password and all that other stuff is variable depending on whether we're an autoconnecting ded or a gui waiting for entry. To solve this I've created a ClientRunner which parses the arguments, initializes the CConfig and then shows the splash if it's required ( this is before a client is launched )

After that we call either MWDed or MWClient, passing in the CConfig and the splash screen ( if enabled) as arguments. This enables me to create a separate data holder which can always be initialized when the client is started. The data holder will keep the CCampaign, Connector and any other data that needs to be globally accessible. The MWClient and MWDed now inherit from a Client superclass which takes care of the common setup.

I've also started coding a data interface. Each data type will implement this interface and it will have functions getData(), setData(data), loadDataFromCache() and refreshData(). The first of these is implemented for OpsData. In conjunction with this I'm creating a FileUtils class for fetching caches and converting any existing file reads to MekwarsFileReader calls.

**Ignore the previous post about the splash if you saw it, it was a silly bug I thought I'd need to construct a separate frame**

Spork
Mekwars Developer
Posts: 3914
Joined: Wed Feb 13, 2008 10:23 pm

Re: Refactoring discussion

Post by Spork »

I like these changes very much.

Make it so!
Never had much, grew up with nothing
But the music, well it was something
Been down and out, I've been on top of the world,
World that keeps on spinning on a turntable.

TubeAlloy
Posts: 141
Joined: Wed Mar 04, 2009 4:07 am
Location: Ireland

Re: Refactoring discussion

Post by TubeAlloy »

As part of this refactor since I'm cutting the client up and creating classes to encapsulate the different responsibilities it's going to change an awful lot of code, I'm revising my refactor estimate up to 10-12 weeks.

The main issue is that since MWClient and MWDed grew to become uberclasses they were treated as the main object for everything which snowballed into most classes taking MWClient as an argument so that they can reference it for strings, convenience methods or anything else.

For the most part these dependencies will be changed to the singletons ClientData or GUIData and I'm going to move all of the static strings and ints to a constants package. Unfortunately until I cut up the MWClient and rewrite the interfaces I won't have anything worth committing since it won't build or run.

TubeAlloy
Posts: 141
Joined: Wed Mar 04, 2009 4:07 am
Location: Ireland

Re: Refactoring discussion

Post by TubeAlloy »

Any objections to renaming IClient to IConnectionHandler and abstracting all of the connection logic into a new class which implements it?

**EDIT** - there already is an IConnectionHandler :shock:

I'll need to do some more digging, my main issue with IClient is I don't think it should be handling processIncoming. Maybe setting up the client as an observer of the connection would be a neater solution

TubeAlloy
Posts: 141
Joined: Wed Mar 04, 2009 4:07 am
Location: Ireland

Re: Refactoring discussion

Post by TubeAlloy »

I've just committed my work to date. All I've done so far is broken up the MWClient and replaced injecting it everywhere. I had started making the code neater and more compact as I was moving it but after 20 hours I decided to start copy-pasting existing code and just get the thing compiling (That was 2 weeks ago! :shock: )

The work of storing globally accessible variables is now taken care of by GUIData and ClientData singletons. I've been refactoring for about 3 weeks solid so there's some classes that will be removed, some that have an example use as a proof of concept ( Eg CachedServerData, OpsData) and a lot of the classes I just copy/pasted the old code which could do with a refactor.

It's an awful lot to look over but any feedback is appreciated, even negative feedback. I'd rather stop now than sink another 8 - 10 weeks of work into this only to find people aren't happy with it.

https://sourceforge.net/p/mekwars/code/ ... velopment/

I've tested that the code compiles and the client will login to a test server when I replace the MekWarsClient.jar with my compiled one. That is the extent of the testing, I'm sure many things are broken please don't view this as anything close to usable right now.

Now for a well earned coffee :D

RhubarbsElleven
Posts: 16
Joined: Wed Jan 30, 2013 12:15 pm

Re: Refactoring discussion

Post by RhubarbsElleven »

Did these awesome changes just stay on the development branch?

Post Reply