class-design

Is it possible to assign an array to a class property by reference rather than a copy?

非 Y 不嫁゛ 提交于 2019-11-29 14:33:11
Background: I designed a TableViewDataSource class that provides an implementation for UITableViewDataSource and UITableViewDelegate . You instantiate TableViewSection objects, which are passed to the TableViewDataSource which are used to configure cells, section headers, handle selection, row insertion, etc. The TableViewSection object has a property called dataSource: [AnyObject]? , which, when set, is used to calculate the number of rows in the section, and provide an object for the cell configuration block: // get the section, dequeue a cell for that section, retrieve the item from the

this pointer to base class constructor?

懵懂的女人 提交于 2019-11-29 11:12:22
I want to implement a derived class that should also implement an interface, that have a function that the base class can call. The following gives a warning as it is not safe to pass a this pointer to the base class constructor: struct IInterface { void FuncToCall() = 0; }; struct Base { Base(IInterface* inter) { m_inter = inter; } void SomeFunc() { inter->FuncToCall(); } IInterface* m_inter; }; struct Derived : Base, IInterface { Derived() : Base(this) {} FuncToCall() {} }; What is the best way around this? I need to supply the interface as an argument to the base constructor, as it is not

The point of an Interface [duplicate]

社会主义新天地 提交于 2019-11-29 10:21:37
Possible Duplicate: How will I know when to create an interface? I'm wondering about the point of using an Interface. Do you use Interfaces? If so, when do you decide to use them and when do you decide NOT to use them? I've currently got interfaces defined for my service layers and my repository layers, but I'm wondering if I'm missing out on other places where they'd be useful. I guess I just don't fully understand their purpose. An interfaces defines a contract. Any class that implements an interface has to fulfil that contract. This means that the class must implement methods defined in the

How many methods can a C# class have

拥有回忆 提交于 2019-11-29 09:16:10
Is there a limitation on number of properties, methods a C# class can have? I do a quick skim at Standard ECMA-334 and did not find any information on it. Before jumping into why a class with many methods are bad design, I want to be more clear on the intention. Of course I will not be writing a class with large number of methods manually. The reason I am asking this is I need to generate a large number of execution units by code. I am debate between have multiple classes with single method or one large class with multiple methods. So for this question, I am only interest if is there a limit

The best way to share database connection between classes

时光毁灭记忆、已成空白 提交于 2019-11-29 07:46:53
I would like to be able to hide my database connection from print_r so I am using a static variable. I have a base class and a few object classes. Ideally they would all share the same database connection. What is the best way of sharing this? The way I have it set up now "works" but it just doesnt feel right. Must be a better way of doing this. (logically the classes shouldnt inherit one another) class base { private static $db; function __construct() { self::$db = new DB(); // our database class $foo = new Foo( self::$db ); // some other class that needs the same connection } } class Foo {

How to share data between separate classes in Java

删除回忆录丶 提交于 2019-11-29 03:05:32
问题 What is the best way to share data between separate classes in Java? I have a bunch of variables that are used by different classes in separate files in different ways. Let me try to illustrate a simplified version of my problem: This was my code before: public class Top_Level_Class(){ int x, y; // gets user input which changes x, y; public void main(){ int p, q, r, s; // compute p, q, r, s doA(p,q,r); doB(q,r,s); } public void doA(int p, int q, int r){ // do something that requires x,y and p

“Public” nested classes or not

独自空忆成欢 提交于 2019-11-28 23:30:08
问题 Suppose I have a class 'Application'. In order to be initialised it takes certain settings in the constructor. Let's also assume that the number of settings is so many that it's compelling to place them in a class of their own. Compare the following two implementations of this scenario. Implementation 1: class Application { Application(ApplicationSettings settings) { //Do initialisation here } } class ApplicationSettings { //Settings related methods and properties here } Implementation 2:

Delegates, can't get my head around them

筅森魡賤 提交于 2019-11-28 20:57:27
Hey, I'm looking for useful resources about Delegates. I understand that the delegate sits in the background and receives messages when certain things happen - e.g. a table cell is selected, or data from a connection over the web is retrieved. What I'd like to know in particular is how to use delegates with multiple objects. As far as I know, specifying the same delegate for an object (e.g. table cell) would cause the same events to be called for both the cells at the same time. Is there anything equivalent to instantiating a delegate for a particular object? Thanks in advance! In Cocoa,

Best practice: ordering of public/protected/private within the class definition?

爷,独闯天下 提交于 2019-11-28 16:17:37
I am starting a new project from the ground up and want it to be clean / have good coding standards. In what order do the seasoned developers on here like to lay things out within a class? A : 1) public methods 2) private methods 3) public vars 4) private vars B : 1) public vars 2) private vars 3) public methods 4) private methods C : 1) public vars 2) public methods 3) private methods 4)private vars I generally like to put public static vars at the top, but then would a public static method be listed ahead of your constructor, or should the constructor always be listed first? That sort of

Ruby - share logger instance among module/classes

寵の児 提交于 2019-11-28 15:15:06
Working on a little Ruby script that goes out to the web and crawls various services. I've got a module with several classes inside: module Crawler class Runner class Options class Engine end I want to share one logger among all those of those classes. Normally I'd just put this in a constant in the module and reference it like so: Crawler::LOGGER.info("Hello, world") The problem is that I can't create my logger instance until I know where the output is going. You start the crawler via command line and at that point you can tell it you want to run in development (log output goes to STDOUT) or