1 / 42

Programming Fundamentals (with C #) part 2

Programming Fundamentals (with C #) part 2. Based on Deitel How To Program slides. C# in Short. Started as a similar language to Java Keep and improved C++ enum safer than in C++ (implicitly converted to int ) Better struct switch – every non empty must end with an unconditional branch

cforrest
Download Presentation

Programming Fundamentals (with C #) part 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Fundamentals(with C#)part 2 Based on Deitel How To Program slides

  2. C# in Short • Started as a similar language to Java • Keep and improved C++ • enumsafer than in C++ (implicitly converted to int) • Better struct • switch– every non empty must end with an unconditional branch • Delegates instead of pointers for event handlers and callbacks • In java callback are interfaces; C++ pointers • Methods can take a variable number of param • Java start using it too in 1.5+ • Autoboxing • Java took it too • Foreach • Java took it too

  3.   C# (cont.) • C# is object oriented • C# is event driven— • programs respond to user-initiated events such as mouse clicks, keystrokes and timer expirations. • Microsoft’s Visual C# is a visual programming language—inaddition to writing program statements to build portions of your applications, you can use Visual Studio’s graphical user interface to conveniently drag and drop predefined objects like buttons and textboxes into place on your screen, and label and resize them.

  4.   The Internet and the World Wide Web • In the late 1960s, ARPA implemented the ARPAnet, the grandparent of today’s Internet. • ARPAnet’s main benefit proved to be the capability for quick and easy communication via what came to be known as electronic mail (e-mail). • This is true even on today’s Internet, with e-mail, instant messaging and file transfer allowing billions of people worldwide to communicate with each other. • Companies started spending large amounts of money to develop and enhance their Internet presence.

  5.  The Internet and the World Wide Web (cont.) • Bandwidth— the information-carrying capacity of communications lines—on the Internet has increased tremendously, while hardware costs have plummeted. • In 1989, Tim Berners-Lee of began to develop a technology for sharing information over the Internet via “hyperlinked” text documents. • He called his invention the HyperText Markup Language (HTML). He also wrote the communication protocol HyperText Transfer Protocol (HTTP) to form the backbone of his new hypertext information system, which he referred to as the World Wide Web orsimply “the web.”

  6.  The Internet and the World Wide Web (cont.) • Thewebis a collection of hardware and software associated with the Internet that allows computer users to locate and view multimedia-based documents (documents with various combinations of text, graphics, animations, audios and videos) on almost any subject. • In 1994, Berners-Lee founded an organization, called the World Wide Web Consortium, devoted to developing technologies for the World Wide Web. • Today’s applications can be written with the aim of communicating among the world’s computers via the Internet and the web. • This is the focus of Microsoft’s .NET strategy.

  7. Introducing async/await • In most programming today, each task in a program must finish executing before the next task can begin. • This is called synchronous programming and is the style we use for most of this book. • C# also allows asynchronous programming in which multiple tasks can be performed at the same time. • Asynchronous programming can help you make your apps more responsive to user interactions, such as mouse clicks and keystrokes, among many other uses. • Visual C# 2012’s new asyncand await capabilities simplify asynchronous programming, because the compiler hides much of the associated complexity from the developer.

  8. Extensible Markup Language (XML) • As the popularity of the web exploded, HTML’s limitations became apparent. HTML’s lack of extensibility (the ability to change or add features) frustrated developers, and its ambiguous definition allowed erroneous HTML to proliferate. • The need for a standardized, fully extensible and structurally strict language was apparent. As a result, XML was developed by the W3C. • Data independence, the separation of content from its presentation, is the essential characteristic of XML.

  9.  Extensible Markup Language (XML) (cont.) • Because XML documents describe data, any application conceivably can process them. XML is increasingly used in databases. • Microsoft’s .NET technologies use XML to mark up and transfer data over the Internet, to enable software components to interoperate and to describe graphical user interfaces.

  10.   Introduction to Microsoft .NET • In 2000, Microsoft announced its.NET initiative, a broad vision for using the Internet and the web in the development, engineering, distribution and use of software. • Developers can create .NET applications in any.NET-compatible language (such as C#, Visual Basic, and others). • Part of the initiative includes Microsoft’s ASP.NETtechnology, allowing developers to create web applications. • Visual programming has become popular because it enables developers to create Windows and web applications easily, using such prepackaged controls as buttons, textboxes and scrollbars. • The .NET Framework executes applications, includes the .NET Framework Class Library and so on.

  11.  The .NET Framework and the Common Language Runtime • The details of the .NET Framework are found in the Common Language Infrastructure (CLI), which contains information about the storage of data types (that is, data that has predefined characteristics such as a date, percentage or currency amount), objects and so on. • The Common Language Runtime (CLR) is the central part of the .NET Framework — it executes .NET programs. • Programs are compiled into machine-specific instructions in two steps.

  12. Two steps

  13. Net Framework

  14. Common Language Runtime • The Common Language Runtime (CLR) • executes .NET programs and provides functionality to make them easier to develop and debug. • The CLR is a virtual machine (VM) – • software that manages the execution of programs and hides from them the underlying operating system and hardware. • The source code for programs that are executed and managed by the CLR is called managedcode.

  15. The .NET Framework and the Common Language Runtime (cont.) • First, the program is compiled into Microsoft Intermediate Language (MSIL), which defines instructions for the CLR. • Code converted into MSIL from other languages and sources can be woven together by the CLR. • The MSIL for an application’s components is placed into the application’s executable file. • When the application executes, another compiler (known as the just-in-time compiler or JIT compiler) in the CLR translates the MSIL in the executable file into machine-language code (for a particular platform), then the machine-language code executes on that platform.

  16.   The .NET Framework and the Common Language Runtime (cont.) • The .NET Framework also provides a high level of language interoperability. • Programs written in different languages (for example, C# and Visual Basic) are all compiled into MSIL—the different parts can be combined to create a single unified program. MSIL allows the .NET • Framework to be language independent, because .NET programs are not tied to a particular programming language.

  17. Platform Independence • If the .NET Framework exists and is installed for a platform, that platform can run any.NET program. • The ability of a program to run without modification across multiple platforms is known as platform independence. • Code written once can be used on another type of computer without modification, saving time and money. • Previously, companies had to decide whether converting their programs to different platforms—a process called porting-was worth the cost. • With .NET, porting programs is no longer an issue, at least once .NET itself has been made available on the platforms.

  18. Language Interoperability • The .NET Framework provides a high level of language interoperability. • Because software components written in different .NET languages (such as C# and VB.NET) are all compiled into MSIL, the components can be combined to create a single unified program. • Thus, MSIL allows the .NET Framework to be language independent. • .NET 4.5 features .NET for Windows Store Apps—a subset of .NET that’s used to create Windows 8 UI (user interface) style apps.

  19. Windows 8/10 • Self study…

  20.   Test-Driving the Advanced Painter Application (cont.) • Running the Advanced Painter application. • Double click the file name AdvancedPainter.exe (Fig. 1.1) to run the application (Fig. 1.2). • Figure 1.2 labels several graphical elements—called controls. These include GroupBoxes, RadioButtons, a Panel and Buttons. The application allows you to draw with a red, blue, green or black brush of small, medium or large size. • The brush’s properties, selected in the RadioButtons labeled Black and Medium, are default settings—the initial settings you see when you first run the application. Default settings also provide visual cues for users to choose their own settings.

  21. Test-Driving the Advanced Painter Application • The Advanced Painter application allows developers to draw with different brush sizes and colors. • Open a Windows Explorer window and navigate to the C:\examples\ch01 directory (Fig. 1.6)— assuming you placed the examples in the C:\examples folder.

  22.   Test-Driving the Advanced Painter Application (cont.) Step 4: Changing the Brush Color • Click the RadioButton labeled Red to change the brush color, then click the RadioButton labeled Small to change the brush size. • Position the mouse over the white Panel, then drag the mouse to draw with the brush. • Draw flower petals, as shown in Fig. 1.9.

  23. Painter Test-Drive in Visual Studio Express 2012 for Windows Desktop (Cont.) Step 5: Changing the Brush Color and Size • Click the GreenRadioButton to change the brush color. Then, click the LargeRadioButton to change the brush size. • Draw grass and a flower stem, as shown in Fig. 1.10.

  24.   Test-Driving the Advanced Painter Application (cont.) • Changing the brush size. • Click the RadioButton labeled Green to change the color of the brush again. Then, click the RadioButton labeled Large to change the size of the brush. Draw grass and a flower stem, as shown in Fig. 1.4.

  25. Test-Driving the Advanced Painter Application (cont.) Step 6: Finishing the Drawing • Click the Blue and MediumRadioButtons. • Draw raindrops, as shown in Fig. 1.11, to complete the drawing.

  26. Painter Test-Drive in Visual Studio Express 2012 for Windows Desktop (Cont.) Step 7: Stopping the App • When you run an app from Visual Studio, you can terminate it by clicking the stop button on the Visual Studio toolbar or by clicking the close box on the running app’s window.

  27.  Introduction to Object Technology • Objecttechnology is a packaging scheme for creating meaningful software units. • There are date objects, time objects, paycheck objects, invoice objects, automobile objects, people objects, audio objects, video objects, file objects, record objects and so on. • button objects, textbox objects, menu objects and many more. • Almost any nouncan be reasonably represented as a software object.

  28. Introduction to Object Technology (cont.) • Objects have attributes (also called properties), such as color, size, weight and speed; and perform actions (also called methods or behaviors), such as moving, sleeping or drawing. • Classes are types of related objects. • For example, all cars belong to the “car” class, even though individual cars vary in make, model, color and options packages. • A class specifies the general format of its objects, and the attributes and actions available to an object depend on its class.

  29.  Introduction to Object Technology (cont.) • An object is related to its class in much the same way as a building is related to the blueprint from which the building is constructed. • Contractors can build many buildings from the same blueprint; programmers can instantiate (create) many objects from the same class. • With object technology, properly designed classes can be reused on future projects.

  30.   Introduction to Object Technology (cont.) • Focus on the behaviors and interactions of objects. • In the same way, an application that’s divided into objects is easy to understand, modify and update because it hides much of the detail. • C# is one of the world’s most widely used object-oriented languages, especially in the Microsoft software development community.

  31.   Introduction to Object Technology (cont.) • BasicObject-TechnologyConcepts • Object-orienteddesign(OOD) models software in terms similar to those that people use to describe real-world objects. • It takes advantage of class relationships, where objects of a certain class, such as a class of vehicles, have the same characteristics—cars, trucks, little red wagons and roller skates have much in common.

  32. Introduction to Object Technology (cont.) • OOD takes advantage of inheritancerelationships, where new classes of objects are derived by absorbing characteristics of existing classes and adding unique characteristics of their own. • An object of class “convertible” certainly has the characteristics of the more general class “automobile,” but more specifically, the roof goes up and down. • Object-oriented design provides a natural and intuitive way to view the software design process—namely, modeling objects by their attributes, behaviors and interrelationships, just as we describe real-world objects.

  33. Introduction to Object Technology (cont.) • OOD also models communication between objects. • Just as people send messagesto one another (for example, a sergeant commands a soldier to stand at attention), objects also communicate via messages. • A bank-account object may receive a message to decrease its balance by a certain amount because the customer is withdrawing that amount of money. • OOD encapsulates (that is, wraps) attributes and operations (behaviors) into objects—an object’s attributes and operations are intimately tied together.

  34. Introduction to Object Technology (cont.) • Objects have the property of information hiding–objectsmay know how to communicate with one another across well-defined interfaces, although they’re not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves. • You can drive a car effectively, for example, without knowing the details of how engines, transmissions, brakes and exhaust systems work internally—as long as you know how to use the accelerator pedal, the brake pedal, the steering wheel and so on.

  35. Introduction to Object Technology (cont.) Classes, FieldsandMethods • Each class contains data as well as the set of methods that manipulate that data and provide services to clients (that is, other classes that use the class). • The data components of a class are called attributes or fields. • For example, a bank account class might include an account number and a balance. The operation components of a class are called methods. • A bank-account class might include methods to make a deposit (increase the balance), make a withdrawal (decrease the balance) and inquire what the current balance is.

  36. Introduction to Object Technology (cont.) • Classesare to objects as blueprints are to houses—a class is a “plan” for building objects of the class. Just as we can build many houses from one blueprint, we can instantiate (create) many objects from one class. • Each class has a potential to become a valuable softwareasset that you and other programmers can reuse to speed future software development efforts.

  37. Introduction to Object Technology (cont.) • Introduction to Object-Oriented Analysis and Design (OOAD) • This approach may work for small programs, but what if you were asked to create a software system to control thousands of automated teller machines for a major bank? • For a project so large an complex, you could not simply sit down and start writing programs. • To create the best solutions, you should follow a detailed process for determining your project’s requirements (that is, what your system is supposed to do) and developing a design that satisfies them (that is, deciding how your system should do it). • Ideally, you would go through this process and carefully review the design (and have your design reviewed by other software professionals) before writing any code. • If this process involves analyzing and designing your system from an object-oriented point of view, it’s called object-oriented analysis and design (OOAD).

  38. Introduction to Object Technology (cont.) • Although many different OOAD processes exist, a single graphical language known as the UML (Unified Modeling Language) for communicating the results of any OOAD process has come into wide use.

More Related