Presentation is loading. Please wait.

Presentation is loading. Please wait.

. Ex4 – preliminary feedback. Comments on Ex4 Cautionary note: u These are observations on some of the submitted exercises u The emphasis is to explain.

Similar presentations


Presentation on theme: ". Ex4 – preliminary feedback. Comments on Ex4 Cautionary note: u These are observations on some of the submitted exercises u The emphasis is to explain."— Presentation transcript:

1 . Ex4 – preliminary feedback

2 Comments on Ex4 Cautionary note: u These are observations on some of the submitted exercises u The emphasis is to explain some issues and hopefully teach you something u This is not a statement of things that need to be fixed for ex5

3 Design issue #1: Graph operations class Graph { … Graph* operator+(Graph const& rhs) const; }; vs. class Graph { … }; Graph *graphUnion( Graph const&, Graph const& );

4 Design issue #2: Encapsulation What is wrong with this? class Graph { public: typedef map VerticesMap; … VerticesMap const& vertices(); … };

5 Design issue #3: iterators u Using STL iterators is perfectly ok class Graph { public: … typedef map ::iterator iterator; iterator begin(); iterator end(); private: map m_Vertices; };

6 Design issue #4: iterators (again) class Graph { vertex* findVertex( string const& name ); } vs. class Graph { iterator findVertex( string const& name ); }

7 Design Issue #5: Iterators (last) u Iterators are supposed to be light-weight u This is not a good example class GraphVerticesIterator { private: Graph* mGraph; Graph::VerticeMap::iterator mi; Graph::VerticeMap::iterator mBegin,mEnd; };

8 Design issue #6: Interface u Graph as a collection of vertices string v1, v2 … graph.findVertex(v1).addEdge(v2); vs. u Graph as a “unified” data structure graph.addEdge(v1,v2);

9 Design Issue #7: Interfaces class vertex { … addIncomingEdge( string const& from ); addOutgoingEdge( string const& to ); }; class Graph { … void addEdge( string const& from, string const& to ) { … // various checks… mEdges.add( Edge(from, to) ); findVertex( from )->addOutgoingEdge( to ); findVertex( to )->addOutgoingEdge( from ); } };

10 . Summary

11 What Have We Learned? u C:  Basic language  Motto: “Simple does it”  Lean (& mean) u C++  High level constructs  Complex type system  Extensive libraray u Practice of Programming

12 C – Language u Architecture  Preprocessor/Complier/Linker  Memory structure & organization  Libraries (static/shared)  Makefiles

13 C – Language u Basic language constructs:  Basic types  Arrays  Functions

14 C - language u “Complex” language constructs  pointers  memory management: malloc/free  pointers to functions  const

15 C - language Standard library  I/O: printf/scanfs  String functions  qsort  binary search  random  atof/atoi

16 C++ - language u Object oriented programming  Classes  Constructors & destructors  Inheritance  Polymorphism – virtual functions, pure virtual classes  this  Encapsulation (private/protected/public/friend)

17 C++ - language u Advanced features  Function & operator overloading  Function resolution  Reference  RTTI  Exceptions  inline  static

18 C++ - language u Generic programming  Templates  STL  Using STL interface (iterators)

19 C++ - Language u Pointers & memory  new/delete  encapsulation of resources  copy ctor, assignment op  smart pointers

20 Practice of Programming u Programming style u Testing u Debugging u Performance u emacs u Makefile u Programming with interfaces u Design patterns


Download ppt ". Ex4 – preliminary feedback. Comments on Ex4 Cautionary note: u These are observations on some of the submitted exercises u The emphasis is to explain."

Similar presentations


Ads by Google