DOC PREVIEW
FSU COP 3330 - Aggregation/Composition Programming in C++

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Aggregation/Composition Programming in C++ Fall 2008Aggregation/CompositionSlide 3Slide 4Slide 5Double Link List ClassStack ClassStack Class Header FileClass Double Link ListSlide 10Slide 11Slide 12Aggregation/Composition Programming in C++Fall 2008 Dr. David A. [email protected]/Composition•Aggregation is the act of embedding an object of one class into another as a member data of another class. •Some developers use the term Composition to refer to a stronger relationship where the embedded object would typically not exist independent of the container class.Aggregation/Composition•Why do this? –Computers are complex machines and the only way we “humans” can deal with them is by layering the complexity. –“Something complex is just really many many simple things put together.” –The idea is to build a general purpose tool that performs some primitive or common function and use this instead of re-writing the code.Aggregation/Composition•Let’s say we want to write a program that uses a “Stack”. •What is a stack? –It is a list.–It has a head where the most current values exist. –You can push things on a stack.–You can pop things off of a stack. –You can ask if the stack is empty.–It would be handy if ask how many items were in the stack. –It would be handy to print the stack.Aggregation/Composition•If a “stack” were the only data structure in existence I would not have a problem. I write a stack class that contains all of the necessary data structures, pointers, variables, etc and continue on my merry way. •However, what about–Queue–Dequeue–Ordered List–Unordered List–Binary Tree–Traverse the list in reverse–Etc.Double Link List Class0482379459999HeadTailCurrStack Class6735974HeadStack Class Header File#ifndef STACK1_H#define STACK1_H#include “dllist.h”class stack:{public void Push(int val);int Pop();bool isempty();int NumItems();void ListStack;};Class Double Link List#ifndef DLLIST1_H#define DLLIST1_Hclass dllist: public:struct dlist_type {struct * prev;int val;struct * next; };dllist (); // constuctordllist (int lo, int hi);struct dlist_type *FindVal(int val);int DelRecord(struct dlist_type *loc);struct dlist_type *InstertVal(int val);struct dlist_type *ReturnHead();struct dlist_type *ReturnTail();int InsertBefore(struct dlist_type *loc, int val);Class Double Link Listint InsertAfter(struct dlisttype *Loc, int val); void ListDLL();struct dlist_type *ReturnCurr();int ReturnNumberInList();private: struct dlist_type *Curr;struct dlist_type *Head;struct dlist_type *tail;int NumberOfRecords;};#endifAggregation/Composition•Things to remember–When an object that has an embedded object is created the constructor runs. •Inside of the constructor of the called class, you must remember to call the constructor of the embedded class! –If there is nothing special, it will invoke the default constructer. –In the case of the double link list, this is not sufficient. –You may not use all of the features of the embedded clas… that’s ok and usually normal.Aggregation/CompositionStack Stack


View Full Document

FSU COP 3330 - Aggregation/Composition Programming in C++

Download Aggregation/Composition Programming in C++
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Aggregation/Composition Programming in C++ and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Aggregation/Composition Programming in C++ 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?