IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Design Pasttern - Strategy Pattern Implemented in Java

4 posters

Go down

Java Design Pasttern - Strategy Pattern Implemented in Java

Post by BIT0122-Amit Wed Jan 26, 2011 2:09 am

Lets consider this scenario-
There is a strategy game, and it has a soldier. The soldier can fight in three different modes. For example, friendly, defensive, and aggressive. When the soldier is required to fight, he will fight in the previously set mode.
If this was an average case, we could've achieved this quite easily. For example, we could simply used an if else or switch case structure and then the algorithms of fighting could be implemented quite easily.
However, this is not the case. This is a pretty big game, and each mode requires thousands of lines of effective codes.
In that case, we are going to divide the work among some developers, so that each one can individually complete the different modes separately. In previous approach, we were going to implement all the hellishly large algorithms in one soldier class. But now, we are going to make an interface, which is going to be implemented by our developers Smile They can work around as much as they want, as long they as override the method defined in the IMode Interface.
This is the Strategy Pattern under behavioural category.
I have created one MainClass, which sets the mode and then commands the soldier to fight. There is a soldier class, which contains some details about the soldier. Finally, There is an IMode Interface and there are three fighting modes which implements the Interface.

MainClass Class:


Solider Class:


Interface Imode:


Aggressive mode class:


Defensive Mode class:


Friendly Mode class:


You can download all codes from [You must be registered and logged in to see this link.]
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Java Re: Design Pasttern - Strategy Pattern Implemented in Java

Post by BIT0112-Rokon Wed Jan 26, 2011 11:59 am

nice and dandy .. Let me do it in assembly ... Razz
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Java Re: Design Pasttern - Strategy Pattern Implemented in Java

Post by BIT0129-Tabassum Sat Jan 29, 2011 3:55 am

Topic moved here from programming and brainstorming Chamber Neutral
BIT0129-Tabassum
BIT0129-Tabassum
Global Moderator
Global Moderator

Course(s) :
  • BIT

Blood Group : A+
Posts : 1496
Points : 2298

http://probe-tabassum.blogspot.com

Back to top Go down

Java Re: Design Pasttern - Strategy Pattern Implemented in Java

Post by BIT0104-ANIK Mon Jan 31, 2011 3:04 am

'aggressive' is the default mode!!!
BIT0104-ANIK
BIT0104-ANIK
Administrator
Administrator

Course(s) :
  • BIT

Blood Group : O+
Posts : 423
Points : 699

http://anikstech.blogspot.com

Back to top Go down

Java Re: Design Pasttern - Strategy Pattern Implemented in Java

Post by BIT0122-Amit Mon Jan 31, 2011 4:03 am

Neutral hmm...
Yeah. typical for a soldier.
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Java Re: Design Pasttern - Strategy Pattern Implemented in Java

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum