Solved

Design Patterns

Posted on 2000-05-14
5
246 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 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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