Pages

Monday, November 21, 2011

On Libraries and Overall Architecture

A very useful tool if you may be reusing classes or large parts of code in different applications is a Library. A Library is a collection of classes one can use simply by adding a:

 using LibraryName.Subfolder;  
 import LibraryName;  

at the top of your code. (using for C# and import for Java). I have many classes i reuse on both the server and client, for example a Class.

##Note: from here on out, Class will indicate an RPG class. class will indicate a code class.

Eg: Class - Mage. I have to reuse a lot of the damage and or stat calculators as i calculate data both client and server side. Instead of simply copying classes from folder to folder and worrying about whether or not both classes are updated on both the server and client, i can simply edit my Mage class on the server and it will update on the client.

THE DOWNSIDE: You cannot address the client or the server from your library code. I'm running into problems where my network streams used to communicate from the client and server cannot speak directly to my client or server code. I have to use a retriever to extract variables from the stream classes. It is a work around, but not the best coding practice. Normally you'd want to use a method from inside the class to pass variables out.

Architecture is something many people over look when building their programs. Of course, the user will never see just how your code works, unless you a) open source it, or b) allow it to be read. (Blizzard has released a viewer so you may read their code, some funny comments in there.) I like designing architectures. The overall structure and order is needed for me. Some developers program as they think up ideas, or some dive right in. But i like to take it step by step. Today improved my class system with a better inheritance:

Classes:
      Caster                                                                                                                              Melee
Healer            Damage                                                                            

Monk,         Tempest, Mage                Knight, Reaper, Titan


Poorly formatted, but you get the picture. Healer and Damage(Caster) inherit class Caster. while at the moment  Knight, Reaper, and Titan inherit Melee. Monk can inherit both Healer and Damage, or just Healer, haven't decided. And Tempest and Mage inherit Damage. This does not mean one Class can only use Healing abilities or Melee abilities. Each Class will be able to use any abiliy, or a large range of them, however, one Class will be better suited to heal or deal melee damage.

Architecture is important, you have to know how your code will work and the most efficient use of code. Languages provide a powerful reuse system already with inheritance. In C# the only thing one must do to inherit is thus:

 public class Mage : Caster  

However , Java must supply a type of inheritance:

 public class Mage extends Caster  
 public class Mage implements Caster  
 The first means you may modify any existing methods in the parent or super class. The second means you are using an interface. More on interfeces later. They are very usefull for RGP's and being able to define many different classes with one statement. (Quick example to clear that up, horrible wording)

EG:

Player testMage = new Mage();
Player testKnight = new Knight();

Player would be the interface here. I'll explain them fully in the next entry. For now, tata.

Push on my friends! Many happy coding adventures.

TNariksan.

No comments:

Post a Comment