class-design

Finding the static attributes of a class in Python

This is an unusual question, but I'd like to dynamically generate the slots attribute of the class based on whatever attributes I happened to have added to the class. For example, if I have a class: class A(object): one = 1 two = 2 __slots__ = ['one', 'two'] I'd like to do this dynamically rather than specifying the argu...

Python's use of __new__ and __init__ ?

I'm just trying to streamline one of my classes and have introduced some functionality in the same style as the flyweight design pattern. However, I'm a bit confused as to why __init__ is always called after __new__. I wasn't expecting this. Can anyone tell me why this is happening and how I implement this functionality otherwise? (apar...

Calling a Class in ASP.NET

Hi I know my ASP.NET but i have to admit, i am dumb with classes and not sure how they work exactly. Also have not worked with them yet but i want to. But what I do know is that it's a place where i can keep code for re-use correct? How will my class look with my code? So this is my code i use on about 3 forms - but i want to save it i...

ASP.NET Partial Page Class Names Best Practices

Hi, When you create a new asp.net page in VS 2008 and choose code behind, it also creates the typical aspx.vb or aspx.cs file to go along with it. At the top of those files, VS names the 'Partial Class' name the file structure and/or name of the aspx file. The question: Is there a best practice for this? Can I just use a single class...

Create class diagram from c++ source?

Is there any free tools available for generating class diagram from c++ source files and if possible for mfc source files too. ...

How to override method to invoke superclass' superclass method?

Part of me thinks that this shouldn't be possible (even if it is), but I'll ask anyway. Given the following class hierarchy (Grandparent and Parent are from a 3rd party and thus, not under my control), how would I override myMethod() in Child such that it bypasses the overridden implementation in Parent and invokes the one in Grandpare...

Class design with N-tier architecture

Hi all, This question follows on very closely to one I asked earlier but I do not think they are the same thing so thought it was sensible to split them up (which is a little ironic when you hear the question). Previous question I have a web application that was split into two projects: 1) The ASP.NET site 2) DLL that contained the b...

Class Design Help

Hi all, I have the following database tables to work with and i am sort of new to oop so i thought i'd ask here. assignment ---------- id person_id assigned_address_id position_id person ---------- person_id current_address_id name ssn drivers_license address --------- id address_number address_street address_city address_state addr...

Why put private fields and methods at the top of class?

I've seen this de facto standard in many places in many languages, but I've never understood it - why put your private fields and methods at the top of a class declaration? Metaphorically it seems like private things should be located at the bottom (hidden) and everything public should be at the top, so that when you read through the cla...

How to decide between C# static and non-static methods?

[Edit] My original-question was "Why to decide between static and non-static? Both do the same..." Unfortunately it was edited to a C#-specific question what I really wanted to avoid. So, let me do some additions: When I say interface, I don't mean the C#-keyword-interface but what I understand something like a C++-interface: A set o...

Model a master template: Inherit or not?

I have a scenario which is not easy to explain, but I am sure it is a very common problem. I will try my best to illustrate the problem. Lets say we have a Survey application which allows us to create surveys. Each survey has its own structure (contains questions, questions are grouped and ordered, etc.). Those surveys are managed by an...

How do I share IDisposable resources within a class?

I'm writing some console applications to move some data between SQLite databases. The classes for the connection and various prepared statements implenent IDisposable, so I'm instantiating these objects using using blocks, like this: using (SQLiteConnection sqlite_conn = new SQLiteConnection(connectionString)) { sqlite_conn.Open();...

How to reduce code duplication on class with data members with same name but different type?

I have trouble when designing classes like this class C1 { public: void foo(); } class C2 { public: void foo(); } C1 and C2 has the same method foo(), class Derived1 : public Base { public: void Update() { member.foo(); } private: C1 member; } class Derived2 : public Base { public: void Update() { member.foo...

Efficient modelling of an MruList in C# or Java

How would you implement a capacity-limited, generic MruList in C# or Java? I want to have a class that represents a most-recently-used cache or list (= MruList). It should be generic, and limited to a capacity (count) specified at instantiation. I'd like the interface to be something like: public interface IMruList<T> { public...

Is it true I should not do "long running" things in a property accessor?

And if so, why? and what constitutes "long running"? Doing magic in a property accessor seems like my prerogative as a class designer. I always thought that is why the designers of C# put those things in there - so I could do what I want. Of course it's good practice to minimize surprises for users of a class, and so embedding tru...

Do we need a new GoF book?

Someone asked What is a Wrapper? and it got me thinking - where would I point a new developer in search of some foundational description of useful patterns? The GoF book has long been a foundational part of the canon for OO programming, and all of us at one time or another have benefited from the descriptions of common patterns there. ...

Organising methods for performing tests - C#

I have a class at the moment and within this class it has 15 or so private methods that perform certain tasks on a loop run by a timer. Some of these methods call of to the database and some don't. The question is...how can I arrange these so that I can setup the class so I can fake a repos or executing process?? This is a simplified ...

Vb.net How can I hide this variable from the rest of the class?

Public Class frmMain Private p_dlgAdd As frmAdd = Nothing Public ReadOnly Property _dlgAdd As frmAdd Get If p_dlgAdd Is Nothing Then p_dlgAdd = New frmAdd() End If Return p_dlgAdd End Get End Property Public Sub DoStuff() ''// Should not touch p_d...

What should I do when a class name is very common?

I've just added yet another 3rd-party component to my .net project that contains a class called Client and it got me thinking about common class names. Do you name your public classes something as common as Client, or do you try to make the name more specific? In the past I would have said Client was fine, since it can always be access...

Is it any good to define trivial inlined methods twice based to debug / release -state of the project?

I've always wondered, if it's good or bad practice to define trivial method twice, depending if the project's on debug / release -state. This is for inlining them. For instance, Foo.h: class Foo { public: ... const bool private: bool _boolean; }; #ifndef _DEBUG /** We'...