Friday, November 13, 2009

Case Study


This post is part of my ongoing effort to familiarize the readers with the commonalities & variabilities of C++/Java/C# programming languages. A tentative outline of this series can be found at Contents.

Programming needs exercises. You can be a good Software Engineer without coding, but to be a programmer you need to write code. Continuous exercise can make you better (nobody is perfect in programming). For all these three languages, we will develop a simple hex viewer program. It should load a file and view the binary contents of it as hexadecimal values. The user should be able to select alternative view types e.g. octal, binary or decimal.

I have sketched a class diagram of the program which is depicted in the following:


HexViewer: It is the main class and will load a file, adjust the size of the display window and manages other objects to print the contents of the file on the window.

DataViewer: It is responsible for printing the hexadecimal contents.

HexConverter: It converts the binary contents of the file into hexadecimal values. The program can be extended with introducing more converter types like Binary converter of binary display, octal converter for octal display, ascii converter for ASCII display.

In my other blogs related to software engineering and test driven development, I will elaborately explain the various stages of SE-lifecycle for developing a software illustrating this program as an example.

Monday, November 09, 2009

Programming Paradigms


This post is part of my ongoing effort to familiarize the readers with the commonalities & variabilities of C++/Java/C# programming languages. A tentative outline of this series can be found at Contents.

The first recognized programming language arrived in 1950s. O'Reily has a nice poster on the history of programming languages. At the beginning programs were very monolithic. The data was global and available to the whole program. Modification to a data item affected the entire program. It was extremely hard to maintain a large piece of code. Various paradigms have been introduced over the years to ease the development of complex programs with higher maintainability and reusability of code. There are other paradigms which represent different concepts for the programmatic elements. In this series of post, we will very frequently state procedural and object oriented programming paradigms. So they demand a bit more explanation.

  1. Procedural
  2. Programs are developed in a collection of procedures or sub-routines. There is an entry procedure (e.g. main in C) that calls other procedures to perform the tasks. The procedures form a chain and together accomplish the intended operations.
    Procedural programming is a type of Structured programming where each procedure has local data and modification of the local data does not affect outside of the procedure. But procedure has access to global data and can modify them which in turn may change the state of the entire program.

  3. Object Oriented
  4. Not surprisingly objects are the most fundamental components for OO programming. An object is a data structure consisting of data and a set of functions to manipulate that data. OO defines a set of objects and interaction among these objects. In the implementation the objects are defined in classes. An object is an temporal instance of a class and each object is unique in its running environment. I have drawn a simple class diagram (Fig. 1) and an example object diagram (Fig. 2) for students and teachers who supervise these students in a school.




 
    Principles of OO
    Abstraction: An skeleton view of the concrete object. Properties important for the external users are separated from the unimportant properties.
    Encapsulation/Information hiding: Implementation details are kept hidden from the external users such that changes should not effect the users.
    Modularity: System partitioned into highly cohesive and loosely coupled components.
    Hierarchy: Ranking or ordering of abstractions. There are a lot of sub-principles how to achieve these principle which is out of the context of this blog.

I will explain the implementation buildup of object orientation in our referenced languages when we will write our first program. The seminal book1 written by Grady Booch and co. is highly recommended for in-depth knowledge of OO concepts.

References

  1. Grady Booch, Robert Maksimchuk, Michael Engle, Bobbi Young, Jim Conallen, Kelli Houston. Object-oriented analysis and design with applications, third edition, Third edition. Addison-Wesley.