21 October 2002 - Current month previous updates: - 07 | 14 | 21 | |
|
Instants (#1) - computer your age, in realtime, with 1 second precision... scary!
Instants (#2) - in the next tutorial, we'll add the graphical interface, but you can already download the final version. |
C# (it reads "c sharp") is a new object oriented language, from Microsoft. C# was born from the .NET initiative, but while other existing languages suffered changes, so they could adapt to the .NET huge family of classes (classes are data types that join properties and methods, the former being what you would call procedures or functions under procedural languages), C# was developed from scratch, so it is probably the best tool to develop .NET applications. In this tutorial, we'll code an application that computes the exact difference between any two instants of the Gregorian Calendar, and displays that difference with 1 second precision, in realtime. The display will be a string with the format "year(s) / month(s) / day(s) / hour(s) / minute(s) / second(s)". The application will have a graphical interface, but today we shall focus in problem's core. First, if we need to work with entities called "instants", we would be grateful for a corresponding data type - we will build such data type, as a class. When building classes you need to ask yourself two questions: #1) what characterizes each object (instance) of the class?, and #2) what commands should objects of the class know to obey to? Second, once you have the high level answer to those questions, implement them, following whatever approach you feel more comfortable with: #1) do a top down observation of the problem; and #2) implement either postponing details (ie, top down all the way), or building up, from details (ie, bottom up, after understanding the problem). My answers to the aforementioned questions, for this specific problem, are #1) a six-tuple (year, month, day, hour, minute, second), defines (characterizes) any instant; and #2) any instant should know the answers to the questions: "is my year a leap year?", "how many days has my month?", "what is my difference, measured in instants, to any other instant?". In the next tutorial, we'll add the graphical interface, but you can already download the executable, and try to design the "looks" yourself, based on what follows, which is the core of the application. Download the "Instants" application (.EXE) [13 KB] Download Microsoft .NET. [various KB, depending on your options] NOTE: in order to run the application, your computer *MUST* have, at least, a minimal .NET installation. So, lets build the class core: class Instant{
} // class Instant ends |
Instants (#3) - for example, just input your birth year, month, day, hour, minute and second (!) and et voila...
Instants (#4) - to put an end to the drama, just press stop. |