The purpose of this post is only for inspecting and enhancing my knowledge, revealing that the resources for most contents from CS246 at the University of Waterloo.
Introduction
Maximize Cohesion Minimize Coupling
Terms
Module
Cohesion and coupling are the concept of the relationships between program's module. Each module should work one small function so that we can re-use and fix code easily.
Cohesion (응집도)
Cohesion reflects how close functions and data in a module are. It measures the amount of relatedness that a module or unit of code contains. A module can be a library package, a file, or a class. We should code with a high degree of cohesion. That means everything in the unit is very closely related and serves a single purpose.
Coupling (결합도)
Coupling measures the amount of dependency between units/modules; how much a module depends on other modules. The more dependency between modules, the more often a change in one will cause a change in another. Low coupling leads to a reduced workload and reduced chance for introducing errors.
Procedural vs Object-Oriented Programming
The code of procedural programming is organized in procedures that implement the logic of the program such as functions and variables that hold the data. However, in object-oriented programming, we implement our programs using objects, which are units of code that contain data and the procedures that implement the logic that operates over the data. Thus, objects are self-contained units of data and code. In OOP, the data contained within an object are called attributes or memeber fields. The procedures of an object are called methods, operations, or member functions.
Classes
Despite that we could keep related data together in C/C++ by putting the into a structure, using the struct keyword, we have alternate way to improve cohesion in C++ but cannot be done in C. We can put functions inside of a structure.