Would hyperion's PacketManager be a factory method pattern?
|
Seen about 10 of them in college, going to read the ones I don't know yet.
Personally, I'd like it if more people started using uml diagrams in their snippets/tutorials instead of just copy and paste code. It would help the programmers who are implementing the tutorial/snippet more to understand how it works and they would actually learn something instead of leeching
Would hyperion's PacketManager be a factory method pattern?
No, because you're not creating objects, you're just hiding and restricting access to the arrays by using:
If the code looked something like:Code:public void handle(IoSession session, Packet packet) { try { packetHandlers[packet.getOpcode()].handle((Player) session.getAttribute("player"), packet); } catch(Exception ex) { logger.log(Level.SEVERE, "Exception handling packet.", ex); session.close(false); } }
And so on, then it would be a factory pattern method.Code:public PacketHandler handle(IoSession session, Packet packet) { switch(packet.getOpcode()) { case 0: return new ....//whatever here. case 1: return new....// and again } throw new IllegalArgumentException(); }
Design Patterns eBook
This book helped me so much while learning design patterns, so I can't help but suggest it to anyone that wants to learn more. It's explained extemely simple, and it's a fun read. I bought it because I wanted to support the people behind it, but you can get it by other means of course.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |