Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Design Patterns

Posted on 2000-05-14
5
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

610 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