473,786 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overloaded Constructors?!?

Hello NG,

I am trying to port a useful class from wxWidgets (C++) to a pure Python/wxPython
implementation. In the C++ source code, a unique class is initialized with
2 different methods (???). This is what it seems to me. I have this declarations:

class wxFoldWindowIte m
{
private:
wxWindow *_wnd;
int _type, _flags;
int _leftSpacing,
_rightSpacing,
_ySpacing;
int _lineWidth, _lineY;
wxColour _sepLineColour;

public:
enum
{
WINDOW = 0,
SEPARATOR
};

// wxWindow constructor. This initialises the class as a wxWindow type
wxFoldWindowIte m(wxWindow *wnd, int flags = wxFPB_ALIGN_WID TH, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTSPACING, int rightSpacing
= wxFPB_DEFAULT_R IGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _flags(flags)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(0)
{
};

// separator constructor. This initialises the class as a separator
type
wxFoldWindowIte m(int y, const wxColour &lineColor = *wxBLACK, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTLINESPACING,
int rightSpacing = wxFPB_DEFAULT_R IGHTLINESPACING )

: _wnd(0)
, _type(SEPARATOR )
, _flags(wxFPB_AL IGN_WIDTH)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(y)
, _sepLineColour( lineColor)
{
};

The 2 different initializations refers to completely different objects (the
first one is a wx.Window, the second one is an horizontal line). Next, there
are a lot of functions that, depending on the variable _type, return properties
of the wx.Window or of the line. I would like to keep the same names for
classes/methods, so it would be useful to have the same class with 2 different
"initialization s".
Does anyone know if is there a way to achieve the same thing in Python/wxPython?
Someone else has talked about overloaded constructors, but I don't have
any idea on how to implement this kind of "constructo rs" in Python. Does
anyone have a small example of overloaded constructors in Python?
I have no idea... Or am I missing something obvious?

Thanks to you all.

Andrea.
Jul 18 '05 #1
1 2382
an***********@t in.it wrote:
Hello NG,

I am trying to port a useful class from wxWidgets (C++) to a pure Python/wxPython
implementation. In the C++ source code, a unique class is initialized with
2 different methods (???). This is what it seems to me. I have this declarations:

class wxFoldWindowIte m
{
// wxWindow constructor. This initialises the class as a wxWindow type
wxFoldWindowIte m(wxWindow *wnd, int flags = wxFPB_ALIGN_WID TH, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTSPACING, int rightSpacing
= wxFPB_DEFAULT_R IGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _flags(flags)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(0)
{
};

// separator constructor. This initialises the class as a separator
type
wxFoldWindowIte m(int y, const wxColour &lineColor = *wxBLACK, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTLINESPACING,
int rightSpacing = wxFPB_DEFAULT_R IGHTLINESPACING )

: _wnd(0)
, _type(SEPARATOR )
, _flags(wxFPB_AL IGN_WIDTH)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(y)
, _sepLineColour( lineColor)
{
};

The 2 different initializations refers to completely different objects (the
first one is a wx.Window, the second one is an horizontal line).
This is a strange design. My first reaction is, why do you want to do that? Maybe you should split
the class in two?

Next, there are a lot of functions that, depending on the variable _type, return properties
of the wx.Window or of the line. I would like to keep the same names for
classes/methods, so it would be useful to have the same class with 2 different
"initialization s".


One way to do this in Python is to have a single constructor that looks at the type / number of
arguments to figure out what it is supposed to do. Another way is to make two factory methods that
create instances of the class and do the correct initialization.

Kent
Jul 18 '05 #2

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

Similar topics

1
2226
by: masood.iqbal | last post by:
I have a few questions regarding overloaded typecast operators and copy constructors that I would like an answer for. Thanks in advance. Masood (1) In some examples that I have seen pertaining to casting class A to class B, the implementation of the
3
1599
by: hazz | last post by:
The following classes follow from the base class ' A ' down to the derived class ' D ' at the bottom of the inheritance chain. I am calling the class at the bottom, "public class D" from a client app with; D m_D = new D(tkn); public class A : MarshalByRefObject public A () <--------------------- public class B : A public B () <----------------------
3
3320
by: mblatch | last post by:
This is probably a C#-101 type question, but I've struck out on finding an answer. I am setting up a class with a few overloaded constructors. Inside those constructors, I would like to call the "default" zero-argument constructor. The compiler gives me an error "PC_StreamBuffer is a type but is used like a variable". I've tried adding "this." in front of references to PC_StreamBuffer(), but that gives another compiler error. A...
3
1711
by: Vera | last post by:
I built a class in VB.NET that has an overloaded constructor. It can either accept nothing, a string or an object Public Sub New( MyBase.New( End Su Public Sub New(ByVal strName As String MyBase.New( '... Do init with strNam End Su
7
1500
by: cmay | last post by:
Can someone quick shed some light on this issue I am having? I wanted to create 2 constructors for my object, one that takes an ID value and one that takes a datarow. If ID value is provided, it is going to get the info from the database and populate itself. If a datarow is provided, then it will use the row to populate itself. So, I wanted to have the "by ID" function get a datarow from the
5
2284
by: sam_cit | last post by:
Hi Everyone, I was just wondering, about the overloaded assignment operator for user defined objects. It is used to make sure that the following works properly, obj1 = obj; so the overloaded operator function performs the necessary copy of obj's member in to obj1. Can't the same be done using copy
3
1933
by: jerry.teshirogi | last post by:
I have the following class and main: ////////////////////////////////////////////////////////// #include <iostream.h> class myVector { public: double x, y, z:
13
1520
by: =?Utf-8?B?QW5kcmVhcw==?= | last post by:
Hi, I would like to get some thoughts on Overloaded constructors vs. Object initializations. Assuming that the class supports a default constructor, is there any reason to include overloaded constructors when you are able to use object initialization? I see a point, to provide the overloads, if you are developing framework code that might support the need to run ontop of 2.x but if you are writing a sealed application / know you are...
6
4171
by: Joe HM | last post by:
Hello - I have a question regarding overloading the New() in a MustInherit Class. The following show the code in question ... MustInherit Class cAbstract Public MustOverride Sub print() Protected mName As String
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.