创建和维护类的重型和轻型版本 [英] Creating and Maintaing Heavy and Light Versions of Classes

查看:56
本文介绍了创建和维护类的重型和轻型版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


我有一个计算密集型类库,由基于GUI的GUI创作应用程序和更简单的非交互式渲染使用

申请。这两个应用程序都需要将类

序列化为相同的文件,但只有GUI应用程序才需要全部的类

方法。


现在,渲染应用程序需要移植到多个操作系统,但GUI

不行。为了减少移植的时间/成本,我想创建两个类的b $ b版本 - 一个只包含数据加上最小的

方法(主要是复制构造加序列化和其他一些)和一个

的全方位方法。


我最初的想法是将简单类定义为基础类和

然后从这些类中派生出完整的类。但是,一些基类

将包含成员,这些成员本身需要简化类型,如果我将它们转换为更简单的类,那么它不是

清楚我如何能够恢复

派生版本中的全部功能。希望有意义;-)


有没有人有任何关于如何处理这个问题的建议 - 会是b / b
模板是一种方式,或者可能是聪明的指针?


谢谢

杰克

Hello

I have a library of calculationally intensive classes that is used both by a
GUI based authoring application and by a simpler non-interactive rendering
application. Both of these applications need to serialise the classes
to/from the same files but only the GUI app needs the full range of class
methods.

Now, the rendering app needs to be ported to multiple OS''s but the GUI
doesn''t. In order to reduce the time/cost of porting I''d like to create two
versions of the classes - one that only contains the data plus minimum
methods (mostly copy-construct plus serialisation and a few others) and one
with the full range of methods.

My initial thought was to define the simple classes as bases classes and
then derive the full classes from these. However, some of the base classes
would contain members which are themselves classes which need to be
simplified and if I converted these to the simpler classes then it''s not
clear how I could recover the full functionality in the derived versions of
these. Hope that makes sense ;-)

Does anyone have any suggestions about how to handle this problem - would
templates be a way around, or maybe smart pointers?

Thanks
Jack

推荐答案

"杰克"写了...
"Jack" wrote...
你好

我有一个计算密集型的库,可以通过基于GUI的创作应用程序和更简单的非交互式渲染应用程序。这两个应用程序都需要将类序列化到/来自相同的文件
但只有GUI应用程序需要全方位的类
方法。

现在,渲染应用程序需要移植到多个操作系统,但GUI不会。为了减少移植的时间/成本,我想创建两个版本的类 - 一个只包含数据
加上最小的方法(主要是copy-construct plus)
序列化和其他一些)和一个完整的方法。

我最初的想法是将简单的类定义为基类然后派生完整的课程来自这些。但是,一些基类会包含成员本身需要简化的类,如果我将这些成员转换为更简单的类,那么我不知道如何
可以恢复这些版本的派生
版本的全部功能。希望有意义;-)

有没有人对如何处理这个问题提出任何建议 - 模板是一种方式,还是
可能是智能指针?
感谢杰克
Hello

I have a library of calculationally intensive
classes that is used both by a GUI based authoring
application and by a simpler non-interactive
rendering application. Both of these applications
need to serialise the classes to/from the same files
but only the GUI app needs the full range of class
methods.

Now, the rendering app needs to be ported to multiple
OS''s but the GUI doesn''t. In order to reduce the
time/cost of porting I''d like to create two versions
of the classes - one that only contains the data
plus minimum methods (mostly copy-construct plus
serialisation and a few others) and one with the full
range of methods.

My initial thought was to define the simple classes
as bases classes and then derive the full classes
from these. However, some of the base classes would
contain members which are themselves classes which
need to be simplified and if I converted these
to the simpler classes then it''s not clear how I
could recover the full functionality in the derived
versions of these. Hope that makes sense ;-)

Does anyone have any suggestions about how to handle
this problem - would templates be a way around, or
maybe smart pointers?

Thanks Jack




如果没有更多信息,很难提出建议,但是我没有b
不要认为记忆管理是你困难的核心,所以

我没看到智能指针有多帮助。模板可能很有用,但

如果不知道课程的详细信息,很难说。


我只想创建两个独立的课程:


struct LightWidget {/*...*/};


struct Widget

{

显式小部件(const LightWidget&){/*...* /}

};


使用LightWidget时全部你必须(GUI)需要(渲染)并创建一个完整的

小部件。 Widget可以从LightWidget中的

数据初始化,或者 - 如果你的设计允许 - Widget可以存储一个

LightWidget对象并在其上构建功能,也许只是

转发一些常见操作(如序列化)。



It''s hard to make a recommendation without more information, but I
don''t think memory management is at the heart of your difficulties, so
I don''t see how smart pointers help. Templates might be useful, but
it''s hard to say without knowing the details of your classes.

I would just create two independent classes:

struct LightWidget { /*...*/ };

struct Widget
{
explicit Widget(const LightWidget&) { /*...*/ }
};

Use LightWidget when it''s all you need (rendering) and create a full
Widget when you have to (GUI). Widget can either be initialized from
data in LightWidget or -- if your design permits -- Widget can store a
LightWidget object and build functionality on top of it, perhaps just
forwarding some common operations (like serialization).




" Derek" <无** @ none.com>在消息中写道

news:bt ************ @ ID-46268.news.uni-berlin.de ...

"Derek" <no**@none.com> wrote in message
news:bt************@ID-46268.news.uni-berlin.de...
<如果没有更多信息,很难提出建议,但我不认为记忆管理是你困难的核心,所以
我看不出多么聪明指针帮助。模板可能很有用,但是如果不了解课程的详细信息就很难说。

我只想创建两个独立的类:

struct LightWidget {/*...*/};

struct Widget
{
显式Widget(const LightWidget&){/*...* /}
当你需要(渲染)时,使用LightWidget并在必要时创建一个完整的小部件(GUI)。 Widget可以从LightWidget中的
数据初始化,或者 - 如果你的设计允许 - Widget可以存储一个LightWidget对象并在其上构建功能,也许只是转发一些常见的操作(比如序列化)。

It''s hard to make a recommendation without more information, but I
don''t think memory management is at the heart of your difficulties, so
I don''t see how smart pointers help. Templates might be useful, but
it''s hard to say without knowing the details of your classes.

I would just create two independent classes:

struct LightWidget { /*...*/ };

struct Widget
{
explicit Widget(const LightWidget&) { /*...*/ }
};

Use LightWidget when it''s all you need (rendering) and create a full
Widget when you have to (GUI). Widget can either be initialized from
data in LightWidget or -- if your design permits -- Widget can store a
LightWidget object and build functionality on top of it, perhaps just
forwarding some common operations (like serialization).




感谢您抽出宝贵的时间...


我遇到的问题是Widget本身包含SubWidget类型的成员

,它还需要一个LightSubWidget对应物。所以问题是

如何从

LightWidget / LightSubWidget对象创建Widget / SubWidget对象 - 以一种可靠且易于使用的方式
维护。


到目前为止,我能想到实现这一目标的唯一简单方法是将所有

括在#ifdefs中的重代码中并设置编译器适当的指示。如果有一些更好的机制来维护两个相关的对象集(在单独的源文件中),那么
会很好。但是有吗?


谢谢

杰克



Thanks for taking the time...

The problem I have is that Widget itself contains a member of type SubWidget
which also needs to have a LightSubWidget counterpart. So the question is
how to create the Widget/SubWidget object from the
LightWidget/LightSubWidget object - in a way which is reliable and easy to
maintain.

So far the only simple way I can think of achieving this is to bracket all
the heavy code within #ifdefs and set a compiler directive appropriately. It
would be nice if there were some better mechanism for maintaining two
related sets of objects (in separate source files). But is there?

Thanks
Jack




杰克写道:

....

Jack wrote:
....
现在,渲染应用程序需要移植到多个操作系统,但GUI不会。为了减少移植的时间/成本,我想创建两个类的版本 - 一个只包含数据加上最小的方法(主要是复制构造加序列化和一些)其他)和一个
与各种方法。
Now, the rendering app needs to be ported to multiple OS''s but the GUI
doesn''t. In order to reduce the time/cost of porting I''d like to create two
versions of the classes - one that only contains the data plus minimum
methods (mostly copy-construct plus serialisation and a few others) and one
with the full range of methods.



....


为什么不完全分离GUI你的数据课程?


Robert


....

Why not separate the GUI completely from your "data" classes ?

Robert


这篇关于创建和维护类的重型和轻型版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆