lecture15 - Problem Solving, Comments, Defensive...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 1 Problem Solving, Comments, Defensive Programming Ideas of use during Project 2 Useful and important ways to comment Assertions, etc. Defensive Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 2 Problem Solving in Computer Programming When you want to do something, figure out who knows what your something needs access to. Put your code where it will have access to what it needs to know or provide that access elsewhere Who Knows What? Those Who Know Do! Event-driven programs start at some event handler. You can follow associations to what you need to access. What Paths can I Follow?
Background image of page 2
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 3 Problem Solving class CHaroldFactory : public CActorFactory { public: CHaroldFactory(); virtual ~CHaroldFactory(); virtual CActor *Create(); }; What if I wanted a pointer to Harold’s head (top)? CActor * CHaroldFactory::Create() { CActor *actor = new CActor(L"Harold"); //… CHead *headt = new CHead(L"Head Top", L"images/harold_headt_blank.png"); headt->SetCenter(wxPoint(55, 109)); headt->SetPosition(wxPoint(0, -31)); headb->AddChild(headt); //… actor->AddDrawable(larm); //… actor->AddDrawable(headt); actor->AddDrawable(mTextBubble); return actor; } 4
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 4 One Approach class CHaroldFactory : public CActorFactory { public: CHaroldFactory(); virtual ~CHaroldFactory(); virtual CActor *Create(); CHead *GetHead() {return mHead;} private: CHead *mHead; }; CHead *headt = new CHead(L"Head Top", L"images/harold_headt_blank.png"); headt->SetCenter(wxPoint(55, 109)); headt->SetPosition(wxPoint(0, -31)); headb->AddChild(headt); mHead = headt; A factory can return more than one thing . This is a useful way for the factory to have pointers to things inside a collection of objects or trees/graphs
Background image of page 4
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 5 Another Approach class CActor { public: //… CHead *GetHead() {return mHead;} void SetHead(CHead *head) {mHead = head;} private: //… CHead *mHead; }; CHead *headt = new CHead(L"Head Top", L"images/harold_headt_blank.png"); headt->SetCenter(wxPoint(55, 109)); headt->SetPosition(wxPoint(0, -31)); headb->AddChild(headt); actor->SetHead(headt); Downsides of this approach?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Programming 6 Suppose… class CStuff { public: CStuff(); virtual ~CStuff(); std::wstring GetStuff(); void SetStuff(); private: std::wstring mStuff; std::wstring mInternalStuff1; std::wstring mInternalStuff2; int mInternalNum; }; class CStuffDlg : public wxDialog { public: CStuffDlg(wxWindow *parent); virtual ~CStuffDlg(); void SetStuff1(const std::wstring &str); void SetStuff2(const std::wstring &str); void SetNum(int n); std::wstring GetStuff1(); std::wstring GetStuff2(); int GetNum(); }; Class with things we need to edit using a dialog box. Dialog box for editing those
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 34

lecture15 - Problem Solving, Comments, Defensive...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online