Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 23:09

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



inheritance vs composition

Discussion on inheritance vs composition within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old 06/21/2013, 13:32   #31
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
you really should be using Interfaces , if you already know that all entities use same common stuff why don't you make them drive from interface!

so eg:
Code:
class IEntity{
virtual public uint32_t getMapId() = 0; // getter
virtual public void setMapId(uint32_t value) = 0; //setter
virtual public uint16_t getX() = 0; // getter
virtual public void setX(uint16_t value) = 0; //setter
virtual public uint16_t getY() = 0; // getter
virtual public void setY(uint16_t value) = 0; //setter
//same for the common stuff
};

class Hero : IEntity{
//then here it will force you to override the methods inside the IEntity.. 
};
why is that useful ? well say you have a Monster/Player/SobNpc those three entities can jump right? so why do you need to make 3 methods of jump for the three when you can have just one?
Code:
void Jump(IEntity entity,uint32_t map, uint16_t toX, uint16_t toY){
    entity.setMapId(map);
    entity.setX(toX);
    entity.setY(toY);
   //send packet to entity...
}
so it's easy now to deal with any type of entities yeah?
Mr_PoP is offline  
Thanks
1 User
Old 06/21/2013, 15:44   #32


 
CptSky's Avatar
 
elite*gold: 0
Join Date: Jan 2008
Posts: 1,443
Received Thanks: 1,175
Quote:
Originally Posted by Mr_PoP View Post
you really should be using Interfaces , if you already know that all entities use same common stuff why don't you make them drive from interface! [..]
There is no point to make a complete interface. Bunch of getters/setters don't have to be reimplemented. You can put them virtual in case of, but not pure virtual.
CptSky is offline  
Thanks
1 User
Old 06/21/2013, 16:57   #33
 
elite*gold: 0
Join Date: Sep 2012
Posts: 775
Received Thanks: 329
@Mr_PoP that's what i was going to do in addition to a simple macro automating get/set but instead of using 3 interfaces (inheriting from each other like hero from entity overriding stuff) i was to use just 1 with a perfectly designed access modifiers (aka what's common for all with same methods is public , some protected and some private) then inherit with the suitable access modifier to each
still can't figure out what is the best design i should use :\

@CptSky why not ? (just want to learn )
go for it is offline  
Old 06/21/2013, 17:45   #34
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
Quote:
Originally Posted by CptSky View Post
There is no point to make a complete interface. Bunch of getters/setters don't have to be reimplemented. You can put them virtual in case of, but not pure virtual.
well IEntity designed to have the COMMON between entities , therefore anyEntity is going to drive from it , has to implement it's methods!
Mr_PoP is offline  
Old 06/21/2013, 18:38   #35


 
CptSky's Avatar
 
elite*gold: 0
Join Date: Jan 2008
Posts: 1,443
Received Thanks: 1,175
Quote:
Originally Posted by Mr_PoP View Post
well IEntity designed to have the COMMON between entities , therefore anyEntity is going to drive from it , has to implement it's methods!
Yes, but a getter... Like most getter are implemented as:

Code:
int getLook() { return mLook; }
Why would you reimplement this method over and over ? It's the same thing for any entity. Plus, you're adding more overhead for a getter due to the vtable.

Methods like jump/walk, etc. I understand. Getter/setters should be inherited, but not reimplemented.
CptSky is offline  
Thanks
1 User
Old 06/21/2013, 18:54   #36
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
Quote:
Originally Posted by CptSky View Post
Yes, but a getter... Like most getter are implemented as:

Code:
int getLook() { return mLook; }
Why would you reimplement this method over and over ? It's the same thing for any entity. Plus, you're adding more overhead for a getter due to the vtable.

Methods like jump/walk, etc. I understand. Getter/setters should be inherited, but not reimplemented.
aha in this cases yeah , I was just giving him an example
Mr_PoP is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
+12 Item Composition
04/10/2011 - CO2 Private Server - 17 Replies
Hi there! My problem is that I can compose my items till +9 with stones like +1 +2 +3 +4 +5 and +6 , BUT , I can't use +7 / +8 stones. So it doesn't work to +12 any item , it works only from +1 to +9. What should I add/modify to get it work till +12 with all kind of stones? Thanks. P.S: I can only generate +12 items by command ( /item 14563 12 7 255 13 13 ) If you are a flamer don't comment.
[rel] composition fix for 5165
12/09/2009 - CO2 PServer Guides & Releases - 7 Replies
#request close/delete moved to my multi-rel thread.
Composition Chart to +12 any one?
11/28/2007 - Conquer Online 2 - 4 Replies
Just like to know if anyone has a "Composition Chart" to +12 items thanks :)
Composition Calculator
09/30/2006 - CO2 Exploits, Hacks & Tools - 14 Replies
Ok, so im a newbie using cotobo for a long time with only a couple of posts. Everybody would want to see if this is clean and all so please somebody scan it. Why did i make this? Well, i liked the one posted on TQ board but one of the feature never got finished (subtracting what you current have). You can check here http://shellz2.future-hosting.net/~sony/c ompose.php This program is written VB and this is my second VB program besides (Hello World) so it's quite ugly and very plain. ...



All times are GMT +1. The time now is 23:10.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.