Page 14 - DCAP505_MODERN_PROGRAMMING_TOOLS_AND_TECHNIQUES_II
P. 14

Modern Programming Tools & Techniques – II




                    Notes                     class ClassA {}

                                          }
                                   You can then create a second namespace, NS3 that derives the class N3.ClassB from NS1.NS2.
                                   ClassA like this:
                                          namespace NS3
                                          {
                                              class ClassB: NS1.NS2.ClassA {}
                                          }
                                   If this construct is too long for you, or if you’re going to repeat it several times, you can use the
                                   alias A for the class NS1.NS2. ClassA with the using statement like so:

                                          namespace NS3
                                          {
                                              using A = NS1.NS2.ClassA;
                                              class ClassB: A {}
                                          }
                                   This effect can be accomplished at any level of an object hierarchy. For instance, you could also
                                   create an alias for NS1.NS2 like this:
                                          namespace NS3
                                          {
                                              using C = NS1.NS2;
                                              class ClassB: C.A {}
                                          }

                                   Modernity

                                   C and C++ provide reliable transportation, but lack some of the features that programmers look
                                   for. This is one of the reasons many developers have adopted the Java language over the past
                                   few years.
                                   C# goes back to the basics and emerges with several features that programmers longed for
                                   in C++. Garbage  collection is one example-everything  gets cleaned up when it’s no longer
                                   referenced. However, garbage collection can have a price. It makes problems caused by certain
                                   risky behavior (using unsafe casts and stray pointers, for example) far harder to diagnose and
                                   potentially more devastating to a program. To compensate for this, C# implements type safety to
                                   ensure application stability. Of course, type safety also makes your code more readable, so others
                                   on your team can see what you’ve been up to-you take the bad with the good.
                                   C# has a richer intrinsic model for error handling than C++. Have you ever really got deep into
                                   a coworker’s code? It’s amazing-there are dozens of unchecked HRESULTs all over the place,
                                   and when a call fails, the program always ends up displaying an “Error: There was an error”
                                   message.

                                       !
                                     Caution  C# improves on this situation by providing integral support for throw, try...catch,
                                     and try...finally as language elements. True, you could do this as a macro in C++, but now
                                     it’s available right out of the box.






          8                                LOVELY PROFESSIONAL UNIVERSITY
   9   10   11   12   13   14   15   16   17   18   19