Wednesday, April 07, 2010

Head First OOA&D!

I'm spending some time during my job search brushing up on my technical skills. I have to commend the authors of the Head First books. I'm currently re-reading Head First OOA&D (Object Oriented Analysis and Design) and this is a fantastic book. Anyone looking to learn/relearn or brush up on UML, Java, inheritance, polymorphism, encapsulation and OOA&D should go pick this book up and read it.... then read it again.

Typically the definitions of anything OOP/OOAD are detailed and complicated. I will try to summarize some of the major considerations in many software architecture scenarios. I have always been big on "REUSE" and keys to making this a reality are having a deep understanding of the following:

Inheritance: Inheritance let's you build classes based on other classes and avoid duplicating code

By carefully designing your application using inheritance you can simplify designs and eliminate wasteful code by reusing classes throughout the application. When you need a new class, your options are to write a new one from scratch, copy an existing class, or reuse an existing class with inheritance. Reusing an existing class with inheritance requires more knowledge, but really is a fundamental concept that needs to be utilized more often to reduce code.

Polymorphism: Polymorphism allows for apps to be more flexible and less resistant to change by allowing subclasses to "stand in" for superclasses

While this may sound related to inheritance (and it is), one key exception is that polymorphism typically happens at run time. This is also more specific to a variable or argument of instances of various classes. When properly used this allows you to call a method that will work differently according to the type of class the object belongs to. This also goes deep to the point of reuse of code in that many times methods can be overridden instead of duplicated.

Encapsulation: Encapsulation is when you protect information in code from being used incorrectly by separating data from application behavior

Typically, objects should reveal the interfaces needed for interacting with the object. Encapsulation allows the details which are not relevant to the use of the object to be hidden, which aides in readability and maintenance of coding.

No comments: