Code Refactoring 14

[ad_1]
Get the Code:

In this part of the code refactoring tutorial, I’ll show you how and when to use the Adapter Design Pattern.

With the adapter pattern we can create a new class without disturbing any other code. On top of that adapters make it easier to swap in code at runtime. They also allow you to communicate with code using method names that make sense to you.

I refactor code sent in by one of you and show you how to add a ton of flexibility.


Posted

in

by

Tags:

Comments

23 responses to “Code Refactoring 14”

  1. Lester Avatar

    Why do we just use the GalaxPrime class to implement the Enemy class rather than the EnemyAdapter class ? Then, we just use the Polymorphism concept.

    Enemy galax = new Galax();
    Enemy galaxPrime = newgalaxPrime ();

    galax.moveShip();
    galax.makeShipAttack();

    galaxPrime.moveShip();
    galaxPrime.makeShipAttack();

  2. Derek Banas Avatar

    Yes you are correct on both points. I don't always perfect the code because I try to keep everything simple. You guys are always smart enough to apply these techniques. I'm happy that you enjoyed them 🙂

  3. Christoffer Avatar

    And you could just do the methods inside the attack in the Galaxy enemy.

    But I think this is awesome 🙂

  4. Christoffer Avatar

    If you had multiple enemies like galax prime, would you create multiple adapters and name them GalaxAdapteer, because you don't want alot of conditionals. Right?

  5. Derek Banas Avatar

    Thank you 🙂 it is nice to see you came back!

  6. Derek Banas Avatar

    Thank you 🙂 Ill do spring and JEE tutorials very soon. I want to finish desktop / tablet development first

  7. wilst Avatar

    I really like your video tutorials. You're a good teacher. Would it be possible for you to teach Spring?

  8. Augustine Tajomavwo Avatar

    Thank you very much. I'll look forward to it. Cheers.

  9. Derek Banas Avatar

    I'm going to do a tutorial on just MVC. It is in the works. Thanks for the request

  10. Derek Banas Avatar

    You're very welcome 🙂 I love your avatar by the way. I have tutorials planned out years from now. I just wish I would have started with the goal to make complete tutorials like I do now.

  11. Derek Banas Avatar

    That's funny 🙂 I do all kinds of crazy tutorials. I'm glad you guys like that. I'm a little out of practice chess wise though.

  12. Imamu Hunter Avatar

    Dude you're a genius. I'm a programmer that is currently trying to focus on being more social so I'm reading all these books. And it turns out my favorite teacher also teaches make social videos as well. Man if you ever make chess tutorials then you would have to be my brother from another mother. Keep up the good work.

  13. Truthiness231 Avatar

    ROFL, OK now I have a whole section of code I wrote some months back that can be fixed up. IDK what the hell I was thinking solving this sort of problem (multiple enemy types, each functioning differently) with a sort of state-machine-esque solution I came up with… There's more than one way to program a solution, but cricky this is method was just so much cleaner. Thanks again Derek!

    (PS: I respect your ambitious goals you've mentioned in the comments and I intend to see them completed ^.^)

  14. Augustine Tajomavwo Avatar

    Hi Derek, thanks a lot for the videos. I have been watching the design pattern videos and its been very helpful. I however want to make a request. I want you to do a video on model/view separation in java. Up till now I still just lump up logic and GUI together with the help of IDEs. I know they say its bad but I just dont know how else. I'd be glad if you commented to let me know if my request is assented or otherwise.

  15. Derek Banas Avatar

    Eventually I want to make a computer from components and make an OS and compiler for it 🙂

  16. Derek Banas Avatar

    คุณมีความยินดี ฉันคิดว่ามันจะตลกโพสต์วิดีโอในช่วงซูเปอร์โบว 🙂

  17. Derek Banas Avatar

    It is all about the flexibility provided when you have numerous different classes that can't be changed. For example, what would you do if code in GalaxianPrime couldn't be changed? An adapter solves problems like that. I hope that helps

  18. kurotatsu81 Avatar

    Does that mean you'll do a series on compilers and OSs eventually as well?

  19. Fredrik Westman Avatar

    I dont really get why we dont just implement enemy directly on galexy prime. Feels just like an extra step to have the adapter

  20. 123japanuser Avatar

    ขอบคุณอย่างจริงใจสำหรับโค้ชวิดีโอ,
    ความสุขมากที่ได้เรียนรู้แนวคิดนี้
    ยังยินดีที่จะรับเงิน แต่อย่างไรก็ตาม
    พระเจ้ารู้รอยยิ้มบนคุณตลอดไป 🙂
    เราทุกคนเพียงเพื่อให้โชคดีที่คุณกำลังโพสต์วิดีโอแม้ในช่วง nfl

  21. Derek Banas Avatar

    Yes it is coming up in coordination with refactoring. I want to cover everything by the end. The goal is a 100% free education on everything by the end 🙂

  22. kurotatsu81 Avatar

    Wow, a Data Structures and Algs tut series as well? Pretty soon you start awarding comp sci degrees at the end of them all. 🙂 Derek for President of the Earth 2013!

Leave a Reply

Your email address will not be published. Required fields are marked *