Tuesday, January 11, 2005

Object Bootcamp - day1

Fred started the session by asking the class to draw a pie chart based on the importance of the concepts of Polymorphism, Inheritance and Encapsulation to OOP. I came up with a figure of 45%Encapsulation, 30% Polymorphism and 25% Inheritance. Most of us were around the same percentages. Fred's opinion was 60% Encapsulation, 30% Polymorphism and 10% Inheritance. He also noted that in the early days, when OOP was introduced, high importance was placed on Inheritance.

He then gave a brief history of how OOP evolved. Initially, finding the right data structure was considered the most important thing to do. It was assumed that once the data structure is correctly identified, then writing a set of behaviors around it is essentially what OOP was all about.

Later Data hiding evolved to be the most important thing. Since changing a datastructure affected several behaviors in the above said method, this turned out to be the challenge. So it was important to hide the data and provide behaviors around it, this is also known as Encapsulation.

We then started to design a Rectangle Class. Fred says it is important to conceptualize for a good OO design. "Jobs" of a class needs to identified first. Every class must have one and only one job, and this should be understood to identify an object. Example of a good job for class Rectangle is: undertands a geometrical object with 4 sides with right angles at all the ends. Examples of bad jobs are ones that have circular reference, jobs that describes the data and jobs that go into implementation details.

When we design objects, we should think of them as having a conversation. Suppose a user of Rectangle class asks the rectangle for the length, the question that we should ask is why? what are you going to do with that. Probably calculate area. In that case, that behavior has to be present in the Rectangle class itself. This is the conversation.

According to Fred, any class whose name ends with "er" or "or" is a bad object and hence bad encapsulation. Also, Manager classes are like real world Manager, they take credit for what they dont do. ;)

Fred likes to see all classes begin with a comment that starts with "understands". Example:
// understands four sided geometrical figure with right angles at all the corners
class Rectangle {
...
}


For tests, usuall "ensures" seems to fit it.

// ensures that Rectangle works fine
class RectangleTest extends TestCase{
...
}


In OOP, the cycle that someone should usually follow is as below:

Task followed by Design, followed by cycles of Test and Code and then finally integrate before proceeding to another task. This cylce should be done as quickly as possible. Fred says this cycle should be over as early as 15 minutes. At the end of 15 minutes, he likes to see the Green bar. The design aspect of this cycle is falsely ignored as not agile/xp but actually is very much part of this cycle. Yes, there is no upfront design as in a traditional waterfall model, but still is an important step where objects are identified, although for a very negligible time period.

5 Comments:

At 8:57 AM, Blogger Suresh said...

Encapsulation is not a by-product of Inheritance/Polymorhism. In fact i can argue the other way around that Encapsulation yields Polymorphism/Inheritance. If you see my later post on Inheritance, you might agree that Inheritance is something that you should not design for, it is just discovered to remove duplication and make the code better.

I didnt quite understand what you meant by "I Exist" concept. But I would say that every class has a very specific job. If you want to reuse that class, it cannot be reused in a context outside of what the job says. For example, in the case of Rectangle class, the same class cannot be used for a Rectangle that is represented in terms of Cartisan points.

And thanks for your comments..

 
At 3:10 PM, Blogger velraj said...

I appreciate you for this blog. Keep sharing more like this. Thanks a lot.
C C++ Training in Chennai
c c++ courses in chennai
C C++ Training in T Nagar
JMeter Training in Chennai
JMeter Course
Appium Training in Chennai
javascript training in chennai
core java training in chennai

 
At 5:50 PM, Blogger Riya Raj said...

Extraordinary Blog.... It looks more creative... Thanks for sharing wit us...
Digital Marketing Course in Chennai
Digital Marketing Course
best digital marketing course in chennai
Digital Marketing Training in Chennai
Digital marketing course in vadapalani
Digital marketing course in porur
Python Training in Chennai
Hadoop Training in Chennai
Big data training in chennai
JAVA Training in Chennai

 
At 3:05 PM, Anonymous bhai sahab said...

The Professional Certification in Business Analytics is a foundation course for students and professionals who want to develop niche data skills for their chosen industry domain or function area. Become a Business Intelligence and Data Visualisation expert and surge ahead in your career. The nine-day Business Analytics certification course covers all the essential Analytical and Statistical techniques for effective business decision making. This programme introduces the student to the basic concepts of Python language.business analytics courses

 
At 9:21 AM, Blogger saran said...

"Valuable one...thanks for sharing..
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery

"

 

Post a Comment

<< Home