Design Pasttern - Strategy Pattern Implemented in Java
4 posters
IITDU Forum :: Academics (BIT) :: Semester 5 :: SE 506
Page 1 of 1
Design Pasttern - Strategy Pattern Implemented in Java
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 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.]
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 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.]
Re: Design Pasttern - Strategy Pattern Implemented in Java
nice and dandy .. Let me do it in assembly ...
Re: Design Pasttern - Strategy Pattern Implemented in Java
Topic moved here from programming and brainstorming Chamber
Similar topics
» Design Pattern study material: Composite Pattern
» Design pattern Assignment - fly weight pattern
» Mediator Design pattern
» Presentation slides of Introduction to Design Pattern
» Referenced book for design pattern
» Design pattern Assignment - fly weight pattern
» Mediator Design pattern
» Presentation slides of Introduction to Design Pattern
» Referenced book for design pattern
IITDU Forum :: Academics (BIT) :: Semester 5 :: SE 506
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford