Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Programming Rabie A. Ramadan vpro/ Lecture 1.

Similar presentations


Presentation on theme: "Advanced Programming Rabie A. Ramadan vpro/ Lecture 1."— Presentation transcript:

1 Advanced Programming Rabie A. Ramadan Rabie@rabieramadan.org http://www.rabieramadan.org/classes/2011/Ad vpro/ Lecture 1

2 2 Welcome Back

3 Class Organization 3 Attendance is very important Assignments Projects Quizzes

4 ILO’s of the Course ILO Acquire the basic knowledge and essential concepts of Java programming including data types, loops, arrays, classes, inner and outer classes, exception handling, the concept of Servlets, Applets, and Swing programming. Discuss the main concepts and Implementation of multithreaded applications. Use the TCP and UDP protocols in network programming and develop a hands-on application related to the topic. Utilize and implement sockets in their programming wherever it is needed. Explore different Web Programming techniques including HTML, JavaScript, XML, and Servlets. Acquire advanced knowledge in C++ programming through learning different advanced skills. Assess C++ Standard Template Library and collections and their importance. 4 After completing the said course, you will be able to:

5 Textbooks 5

6 Class Organization 6 Some concepts will be introduced by myself (when it is needed) Class work every lecture Please form groups of 5 - Those groups have nothing to do with the project groups Please bring your laptops every lecture Tow items from “Effective C++” book every lecture Based on your naming list, every 5 of you will prepare a presentation.

7 Topics to be Covered 7 Templates STL Threading Network Programming Exception Handling Web Programming

8 Agenda 8 Introduction and Course Motivation Project Items 5 and 6

9 Introduction and Course Motivation 9 Computer Programming is the art of making a computer do what you want it to do.

10 Who are You ? 10 Just a coder Most of us are coders not programmers Programmer Writes an efficient code

11 Project 11 Project 1 Project 2 Project 3

12 Items 5 and 6 12

13 Why??? 13 “Used without discipline, however, C++ can lead to code that is incomprehensible, unmaintainable, inextensible, inefficient and just plain wrong.”

14 Know what functions C++ silently writes and calls. 14

15 Item 5 15 When is an empty class not an empty class? When C++ gets through with it. If you don't declare them yourself, compilers will declare their own versions of a copy constructor, a copy assignment operator, and a destructor. If you declare no constructors at all, compilers will also declare a default constructor for you. All these functions will be both public and inline

16 Item 5 (continue ) 16 class Empty{}; becomes: class Empty{ public: Empty() {... } Empty(const Empty& rhs) { … } ~Empty() { … } Empty& operator=(const Empty& rhs) {…} };

17 What do they do? 17 Copy constructor and assignment generally do a field-by- field copy. These functions will not be written if your class includes a const value or a reference value (compiler isn’t sure how to handle). template class NamedObject { public: NamedObject(std::string& name, const T& value); private: std::string& nameValue; const T objectValue; };

18 Item 6: Explicitly disallow the use of compiler- generated functions you do not want 18

19 Explicitly disallow the use of compiler- generated functions you do not want 19 By declaring member functions explicitly, you prevent compilers from generating their own version. By making a function private, you prevent other people from calling it. – don’t define them, so anyone who tries will get a linker error Even better, put functions in parent class, if child class attempts to call will generate a compiler error (earlier detection is better).

20 Example 20 Real estate agents sell houses, and a software system supporting such agents would naturally have a class representing homes for sale: class HomeForSale {... }; Every property is unique — no two are exactly alike The idea of making a copy of a HomeForSale object makes little sense. How can you copy something that's inherently unique? So, you can not make a copy from HomeForSale class

21 Example (Continue) 21 HomeForSale h1; HomeForSale h2; HomeForSale h3(h1); // attempt to copy h1 — should // not compile! h1 = h2; // attempt to copy h2 — should not compile! How do you do that? Do not implement the copy constructor or the assignment operator Because the compiler will do it for you In reality  they do compile even if you do that why? Because the compiler will do it for you

22 Example (Continue) 22 So, By declaring member functions explicitly, you prevent compilers from generating their own version. (declare it to prevent the compiler to generate it for you) What about the calling class  somebody inherited your class and called the copy constructor. So, declare them as private Well, member and friend functions can still call your private functions

23 Example (Continue) 23 So, Even better, put functions in parent class, if child class attempts to call will generate a compiler error (earlier detection is better). It means declare the function but not implement it

24 Example (Continue) 24 class Uncopyable { protected: Uncopyable(); ~Uncopyable(); private: Uncopyable(const Uncopyable&); Uncopyable& operator=(const Uncopyable&); };

25 Reading Assignment 25 Chapters 4 and 5


Download ppt "Advanced Programming Rabie A. Ramadan vpro/ Lecture 1."

Similar presentations


Ads by Google