472,326 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,326 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 2318
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...
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....
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...
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...
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...
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...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.