class-design

Should I instantiate a collection or inherit from collection?

妖精的绣舞 提交于 2019-12-12 10:54:30
问题 I've asked myself this question a number of times when creating classes, particularly those involving collections, but I've never come up with a satisfactory answer. It's a OOP design question. For example, in a checkbook register program say I have a class of BankAccount . BankAccounts contain data involving the Name of the account, the Type of account (enum of Checking, Saving,...), and other data, but most importantly is a collection of the Adjustment s (deposits or withdrawals) in the

Foward declaration of classes in Python

不羁的心 提交于 2019-12-12 02:04:04
问题 The following program can run successfully: class Simple(object): def __init__(self, name): self.name = name def __add__(self, other): c = Composite() c._members.append(self) c._members.append(other) return c def __repr__(self): return "Simple('%s')" % self.name class Composite(object): def __init__(self): self._members = [] def __add__(self, obj): if isinstance(obj, Simple): out = Composite() out._members = [k for k in self._members] + [obj] elif isinstance(obj, Composite): out = Composite()

How to design shape class

為{幸葍}努か 提交于 2019-12-12 01:34:41
问题 I want to design shape class. I need to distinguish several different shapes: -Point -Line -Triangle -Circle -Polygons The main purpose of this class is to calculate distance between two shapes. I've all methods for calculating those distances, but I want to have a single method that can be used, it should looks like this: float Distance(Shape a, Shape b) Simplest way to do it is to put a lot of if statements and then invoke proper method but this is deffinitely not OOP. How to design such

framework give me error about cannot started directly

人盡茶涼 提交于 2019-12-12 01:17:14
问题 i created web project, and added new class library for framework. This framework includes DAL. But added reference . And running no this give me no fail. runnig give me error: " A project with an Output Type of Class Library cannot be started directly In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project " please please help me... 回答1: You get this error because the project for the

Why does referencing break when done through pointers

笑着哭i 提交于 2019-12-11 16:45:43
问题 i have a referenced default constructor for a class test. class test { public: test(int &input1) : int_test(input1) {}; ~test() {}; int & int_test; }; Then 2 more classes which interact with test as follows: class notebook { public: notebook() {}; ~notebook() {}; int int_notebook; }; class factory { public: factory() {}; ~factory(){}; notebook *p_notebook; }; If i intitalise test (t2) with an integer, this works as expected: int _tmain(int argc, _TCHAR* argv[]){ int var=90; test t2(var); cout

C++ Singleton/Active Object Paradigm

纵然是瞬间 提交于 2019-12-11 16:21:47
问题 I was wondering how you would make a class where you create several instances i.e Session o1 = new Session(); Session o2 = new Session(); You could then make these sessions the active session like so. o1.makeActiveSession(); Session::setActiveSession(o2); Then at any point in my code I could go: Session::getActiveSession(); and it would return the active session object or create new one if one doesn't exist. Only one session can be the active session at any one time, so if a session is told

Class design: entity ID vs entity reference

陌路散爱 提交于 2019-12-11 12:59:16
问题 If I've got Foo with a property of type Bar. Both are persisted in a database which can be retrieved by an ID. (The IDs are actually used in the line of business by customer service claims. So they're not just index placeholders.) I could take the approach shown with b1 or b2. Chaining entities together scares me since if you push that too far, it's easy to get Null's popping up. On the other hand, having the ID show up everywhere seems like it's adding unnecessary wordiness. int fooKey = 123

Am I trying to Implement Multiple Inheritance. How can I do this

给你一囗甜甜゛ 提交于 2019-12-11 12:49:49
问题 I have created a class say A which has some functions defined as protected. Now Class B inherits A and class C inherits B. Class A has private default constructor and protected parameterized constructor. I want Class B to be able to access all the protected functions defined in Class A but class C can have access on some of the functions only not all the functions and class C is inheriting class B. How can I restrict access to some of the functions of Class A from Class C ? EDIT: namespace Db

Is there a specific name for the node that coresponds to a subtree?

核能气质少年 提交于 2019-12-11 12:33:14
问题 I'm designing a web site navigation hierarchy. It's a tree of nodes. Nodes represent web pages. Some nodes on the tree are special. I need a name for them. There are multiple such nodes. Each is the "root" of a sub-tree with pages that have a distinct logo, style sheet, or layout. Think of different departments. site map with color-coded sub-trees http://img518.imageshack.us/img518/153/subtreesfe1.gif What should I name this type of node? 回答1: How about Root (node with children, but no parent

c++ understanding size_t behaviour for vector creation

為{幸葍}努か 提交于 2019-12-11 09:33:52
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 5 years ago . this is a folow up to this https://softwareengineering.stackexchange.com/questions/256241/c-coding-practice-class-vs-free-functions question I posted a few day ago. In short, the idea is to create a custom vector class for statistical data analysis. I got a great response, that made me realise that I need to understand: why use size_t in a constructor of a