Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
If you see errors or additions please respond. Or if you have questions ask, someone will answer them.
Here are my notes on the requirements for the SCJPtest from section 5 of the sun requirements. Point 1. as below.
Section 5.1 Develop code that implements tight encapsulation, loose coupling, and high cohesion in classes, and describe the benefits.
These three principles (encalsulation, cohesion, and coupling) are the basis of good programming for OO applications. To write good OO applications you need to follow these three principles. They are related to each other, so improving the status of one often improves the status of the other two.
Encapsulation is the combining of methods and data into one data structure called a class. You should add the phrase �and hiding the implementation of the data from the user.� The definition for encapsulation then includes data hiding but the two belong together. Encapsulation is the way data hiding is accomplished and this is one of two basic tenets of the entire OO approach to programming. The word tight here could be defined as hidden, as in tight encapsulation means hidden data.
Coupling by definition is the information that is passed back and forth that changes the state of a class or object. More generally it is the sharing of data between classes and methods. Here loose coupling means minimal coupling or the less data passed back and forth the better. A good principle of programming and design is to pass only the information needed by the method. When more information is passed back and forth (especially control arguments) the more likely changes to the state of the object become and thus data hiding is affected. A control argument for instance could provide direction to a method to change the instance variables value belonging to an object thus making private data, public data. Not a good programming practice. So encapsulation and coupling are interrelated.
Cohesiveness can be defined as the relatedness of data to data or methods to data. When classes are formed data and methods that operate on that data are placed into a single class. Data and methods which are closely reated are placed into one class while data and methods not closely related are placed into other classes. High cohesion means the data and methods are highly related to one another. When this is done there is less need for increased coupling or breaking encapsulation because the data and methods needed are all in one place.
Directions for achieving these three principles include: 1. keep data private. 2. use mutator and accessor methods. 3. break up classes which are vague or have too many responsibilities. 4.) 4. minimize the arguments for methods, both data and message. 5. not all fields require mutator and accessor methods. 6. a method should access only its own and never another objects. 7. try to minimize the classes that know about or use each other.
The benefits of these three principles include: 1. when using mutator methods only mutator methods needs changing. 2. easier to maintain. 3. increases reuse. 4. increases reliability 5. reduces data dependency. 6. reduces debugging time.
If you see things that should be added let me know.