Download presentation
Presentation is loading. Please wait.
Published byGregory Perry Modified over 9 years ago
1
CS212: Object Oriented Analysis and Design Lecture 4: Objects and Classes - I
2
Recap to Lecture 3 Introduction to objects and classes Identification of classes and object Class Responsibility and Collaboration
3
3 A CRC card: SnackItem Class name: SnackItem ResponsibilityCollaborator Knows its price and calories
4
A CRC card: Vending Machine 4 Class name: VendingMachine ResponsibilityCollaborator Maintains a collection of SnackItems. Allows addition and removal of SnackItems
5
The Advantages of CRC Model The experts do the analysis User participation increased. Breaks down communication barriers It’s simple and straightforward It’s non-threatening to users It’s inexpensive and portable It goes hand-in-hand with prototyping It leads directly into class diagramming
6
Disadvantages It’s threatening to some developers It’s hard to get users together CRC cards are limited
7
Case study 2: ATM An Automated Teller Machine (ATM) allows bank customers to perform a number of financial transactions: to withdraw and deposit funds to an account, query the balance of any account. The ATM offers an user interface with a display screen, keypad, cash dispenser, deposit slot and a card reader. Once a customer’s card is verified, the customer can query to see the balance in all her account (s), deposit, withdraw or transfer money from one account into another.
8
Case study 2: ATM An Automated Teller Machine (ATM) allows bank customers to perform a number of financial transactions: to withdraw and deposit funds to an account, query the balance of any account. The ATM offers an user interface with a display screen, keypad, cash dispenser, deposit slot and a card reader. Once a customer’s card is verified, the customer can query to see the balance in all her account (s), deposit, withdraw or transfer money from one account into another.
9
Example: GradeBook A gradebook is one which an instructor uses to keep student test score.
10
Creating the blue print in C++ Defining a class Access specifier Function header
11
Executing the blue print
12
Data Members, get and set functions Attributes are represented as variables – data members Each object of a class maintains its own copy of attributes in memory Get function: used to obtain the value of a member variable, e.g. getStudentName(int id) Set function: used to assign a value to a member variable, e.g. setStudentName(string sName) mutators accessors
13
Access Specifiers PublicPrivateProtected Class members declared under public will be available to everyone No one can access the class members declared private outside that class. It makes class member inaccessible outside the class, except its subclass. Access specifiers in C++ class defines the access control rules.
14
Best practices Data members to be declared as private Member functions to be declared as public Access specifiers must not be mixed Explicit use of access specifiers Easy to localize the error while debugging
15
Software engineering with get and set function Private access specifier facilitates data hiding Public set and get function allows clients to access data, but not indirectly Class may store data in one way, however shows to the client in a different way Get and set function helps the client to interact with the object The private data member remains safely encapsulated
16
Reusability When packaged properly, classes can be reused by programmers Function ‘int main(void)’ already has a body Redefinition of ‘int main()’ Placing the main in the same file where the class is defined prevents reuse Use of header files
17
Software engineering issues The entire implementation of the class is revealed to the clients To access object of a class, client should only know, Which function to call What are the parameters to be passes What is the expected return type How the function is implemented is not important to the client
18
Class Interface Header files supports reusability Interface defines and standardize the way in which things such as people and system interacts with each other Interface of a class defines what services a client can use and how to request those services However, NOT how the class carry out those services A classes interface consists of the public member functions
19
Separating Interface from Implementation It is better software engineering to define member functions outside the class definition Their implementation can be hidden from the clients code This practice ensures that programmers do not write client code that depends on the class’s implementation
20
Thank you Next Lecture: Classes and Object - II
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.