Solved

Design Patterns

Posted on 2000-05-14
5
242 Views
Last Modified: 2013-12-03
I have written my own string library in C++ and have been asked to apply the bridge pattern to it in order to split the interface of the string class from its implementation.

I am unsure exactly how this is done and would appreciate some guidance on what would be envolved.  My knowledge of C++ is limited at this time, but I am trying to learn it.
0
Comment
Question by:checkin
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 2808555
This is not the best example for the bridge pattern.  If this is for an assigment, I don't think it was well-conceived.

I guess in this case the best you can do is to provide an abstract base class that performs "primitive" operations--very simple operations on the string.  A few I could think of are

*set string length.
*get string length.
*set character at specified position.
*get character at specified postion.

These 4 operations are probalby the only ones you have to have, but a few more might make things easier.  However the idea is to keep the number of operations, and their complexify down.  And note that these operations are to be generic in nature, i.e. they should be general enough that they can work for any string implimentation.  So for example an operation that retreived a string's reference count would not be permitted, because some implimentations might not use a reference count.  An operation to set value of the terminator character used to mark the end of the string would also not be allowed, since some implimentations might not use a terminator character to mark the end of the string.

continues
0
 
LVL 22

Expert Comment

by:nietod
ID: 2808569
Now from this base class you need to define 1 or more (preferably at least 2 or this whole exercise is pointless) concrete classes.  These classes define  the operations declared in the base class.  Each class should be using a different implimentation for the string.  2 I can think of is that one class might use a NUL (0) character to mark the end of the string while the other class might instead store the length of the string as integer in oen of its data members.  

Now your string class needs to store a pointer to a bridge object,  The type of the pointer will be declared as a pointer to an object of the base bridge class, but actually the object it points to will be one of the derived classes.

Now all the operations in the string class that need to access the string in some way, need to do so through this bridge object.  i.e if the string class has a function that returns the string's length, the function now needs to call the "get length" function of the bridge object.  if the string class has a operator [] function that returns the character at a specitied postion, then the function must be written to use the bridge's "get character at specified position" function.

Let em know if you have any questions.
0
 

Author Comment

by:checkin
ID: 2836209
Hi !

I have read your comments, I think I understand but I am unsure of the class hierachy, how would the classes be organised ?

Would it be possible to provide a shell framework ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2836489
Why don't you try it and post what you get done?   Start with the abstract class for the bridge--this is a class with 4 undefined pure virtual functions.   Then derive a class or two from this that impliments the 4 functions.   Then make your string class use this class.
0
 

Author Comment

by:checkin
ID: 2836882
ok thanks, I will try and post something to you within the next day.

Marvin.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
crystal report check box and wingdings font 7 242
Setting nameservers after res_init fails doing res_query 2 119
Issues with C++ Class 19 107
Gaming Software 1 29
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question