cs31 lecture 17

Are public when then an instance of this class can be

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s/attributes private by default 137 Example (better) class Printable { std::string content; // this is private by default std::string public: Printable()
 { Printable()
 content = “undefined”; content } ~Printable()
 { ~Printable()
 /// do nothing. / } Printable(const Printable& p)
 { Printable(const /// do nothing. / } /// return a constant reference to content (the object cannot be / const std::string& getContent()
 { return content; } /// takes a constant reference to the argument / void setContent(std::string& c)
 { content = c; } void }; modified)
 138 Good design habits revisited x A user should not be allowed to read/write the attributes of user a class class x The developer should provide methods to read/write the The attributes attributes Accessor (to access the data)
 Mutator (to alter the data)
 x The usage of references and const is desired (but not The required)
 x Use “class”, and make public Use constructors/destructors/accessors/mutators/methods 139 Inheritance vs. Attributes x When a class A inherits from B, then all public methods of When B are available as public methods of A (unless redeclared)
 are x When a class A has as attribute a class B, public methods When of B are accessible only if the attribute is publi...
View Full Document

This note was uploaded on 04/03/2014 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Ask a homework question - tutors are online