473,382 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Which design pattern to choose in this situation?

I want to design an image processing class as follow:

class Image
{
Image Data;
General Image Operations;
read(filename, File_Type);
write(filename, File_Type);
};

The Image Data is initialized by the read function according to the
File_Type, and save to a file by write function according to the File
Type.

The problem is:
Whenever adding a file type, I have to add two functions(read and
write) to the class Image.
I want to know if there is a design pattern which bring less
modification to the class Image when adding a file type.

Any suggestion will be appreciated!

Apr 8 '06 #1
4 2421
class Image
{
Image Data;
General Image Operations;
read(filename, File_Type);
write(filename, File_Type);
};

No offence intended, but you don't know what you're doing. I suggest you
read up on some good examples of writing classes.
-Tomás
Apr 8 '06 #2
Guch Wu wrote:
I want to design an image processing class as follow:

class Image
{
Image Data;
General Image Operations;
read(filename, File_Type);
write(filename, File_Type);
};

The Image Data is initialized by the read function according to the
File_Type, and save to a file by write function according to the File
Type.

The problem is:
Whenever adding a file type, I have to add two functions(read and
write) to the class Image.
I want to know if there is a design pattern which bring less
modification to the class Image when adding a file type.

Any suggestion will be appreciated!


I think more generic approach would be to design a special ImageReader
class and derive all particular image readers from it. Then, any time
you need to read an image, you instantiate a particular reader and give
its pointer/reference to the image. The interaction between the image
and the generic reader is the difficult part to design. But it would
be best for this particular situation, I think.

V
--
Please remove capital As from my address when replying by mail
Apr 8 '06 #3
In article <11**********************@g10g2000cwb.googlegroups .com>,
"Guch Wu" <gu****@gmail.com> wrote:
I want to design an image processing class as follow:

class Image
{
Image Data;
General Image Operations;
read(filename, File_Type);
write(filename, File_Type);
};

The Image Data is initialized by the read function according to the
File_Type, and save to a file by write function according to the File
Type.

The problem is:
Whenever adding a file type, I have to add two functions(read and
write) to the class Image.
I want to know if there is a design pattern which bring less
modification to the class Image when adding a file type.

Any suggestion will be appreciated!


I don't think there is any way to do what you want. There are things
that you can do to limit the size of the read and write functions by
reusing like structures within them, but the only way to eliminate
needing them is to make some read only or write only (depending on what
you are writing, this may be a good idea anyway.)

I suggest, however, that you read up on the Strategy pattern.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Apr 8 '06 #4
Guch Wu wrote:
I want to design an image processing class as follow:

class Image
{
Image Data;
General Image Operations;
read(filename, File_Type);
write(filename, File_Type);
};

The Image Data is initialized by the read function according to the
File_Type, and save to a file by write function according to the File
Type.

The problem is:
Whenever adding a file type, I have to add two functions(read and
write) to the class Image.
I want to know if there is a design pattern which bring less
modification to the class Image when adding a file type.

Any suggestion will be appreciated!

I agree with Victor, keep the read/write operations out of the class.

There are many ways to do this, one approach would be to use some for of
raw image object which only has read and write members. You could pass
a reference to one of these to your Image constructor, or make your
Image a template, or provide streaming operators, or....

If you follow Test Driven Development, you design will find the most
appropriate design pattern, don't tie your self to a pattern too early.

--
Ian Collins.
Apr 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: MasterBlaster | last post by:
We are in the initial stages of design analysis and I'm trying to come up with some ideas on how to handle the feature our users are requiring from the new application. We are using VB.NET/window...
3
by: Steve | last post by:
Hi, I just know there must be some kind of well-known design pattern here, but I'll be damned if I can find it... Let me explain my situation. I have a hierarchy of classes for a GUI. All...
27
by: Sune | last post by:
Hi! Pre-requisites: ------------------- 1) Consider I'm about to write a quite large program. Say 500 K lines. 2) Part of this code will consist of 50 structs with, say, no more than at most...
2
by: Matthew Hood | last post by:
My company has expressed a desire to convert an existing MS Access application to a full VB.NET application. My experience is with VB6 so I want to ask a few questions and get some input on the...
6
by: pitachu | last post by:
Hi, I'm not an expect in .NET, so would anyone know an answer a design pattern for the following? There are many customers that require minor customizations to the program I will be...
11
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure...
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer....
2
by: LarryTheSoftwareGuy | last post by:
Folks, Would love some suggestions re what design patterns to use for this situation. I need to create a simple FSM. A certain login scenario will behave differently based on the following:...
6
by: perhapscwk | last post by:
.... ... ... Both of the procedures have repeating sections of code: sending an e-mail and adding a log entry. Task: *1.Select a design pattern (substantiate your choice) that would allow...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.