protected data members
hi, why "data members" should be declared "protected"?what can be the possible benifits? ...
hi, why "data members" should be declared "protected"?what can be the possible benifits? ...
Is there a reason to use a 100% abstract class and not an interface ? Can you give me a good example when to use both so I can grasp the concept a little? Update: 100% Abstract class -> abstract class with only abstract methods. I'm curios if there are differences between php and java regarding this aspect. Update2: Even if I understan...
Why setters are bad in interfaces if we are speaking about domain objects? Clarification: I have a domain object which stores in db. It has several fields which is very costly to set. I.e. class JurasicPark { private long area; ...other fields ... getters and setters .... private Collection<Dinosaur> dinosaurs; privat...
I have a generic editor in ASP.NET page for editing lookup values for different database tables. The code behind uses a base class which handles 99% of the work across all the different lookups in the system. A C# class is passed in to the base class from the code behind as below. public class LookupPageBase : System.Web.UI.Page ...
Hi, Say i have a class hierarchy of domain objects with one base class and a couple of child classes, one level. Let say I have a list of those objects (list of the base class) and I want to apply some logic to the classes that I feel don't really belong to the classes (eg. design/UI specific code). What are my alternatives ? If-is ...
The difference between struct and class is small in C++, basically only that struct members are per default public and class members are per default private. However, I still use structs whenever I need pure data structures, for instance: struct Rectangle { int width; int height; }; I find that very convenient to work with: ...
The first approach that comes to my mind is to put the singleton object in the appDelegate object as property. In this way you can access it from anywhere using #import "myAppDelegate.h" // ... [[(myAppDelegate *)[UIApplication sharedApplication] delegate] SingletonObj] The downside is you have to explicitly cast and import the header...
I'm developing a web application in ASP.NET MVC with NHibernate. Based in articles and tutorials I've found at Google, I'm using Repository for my classes. I have 10 classes and 10 repositories. Today I figured out that 90% of mine repositories are exactly equal each other, except for the class. This is one example: public class Promo...
For a long time I have been throwing around the idea of making my JavaScript more object oriented. I have looked at a few different implementations of this as well but I just cannot decide if it is necessary or not. What I am trying to answer are the following questions Is John Resig's simple inheritance structure safe to use for prod...
Let's say I have to implement a program for a small clinic company that allows its users(this is, the doctors) to schedule consults, log clients medical histories, etc. So, this will probably be the standard 3-layer application: Presentation, Controller and a Data Layer (that'll connect to a database). I see 3 possibilities: My first ...
I have the following hierarchy of classes in a problem that I am working on. DiscountEvent DiscountGroup ProductFamily Product where each class contains a collection of next one (e.g. DiscountEvent contains a collection of DiscountGroups, etc) This kind of a somewhat deep hierarchy results in many chained calls from the h...
I was just going through some codes of C++. Where in I came across the concept of reinterpret_cast operator. EDIT 1 : I know that accessing private members of a class is not recommended. But in some situations we ought to go ahead and access them. I have just put forth this question to get my concepts clear. In the example that I re...
How can i perform dependency injection without breaking encapsulation? Using a Dependency Injection example from Wikipedia: public Car { public float getSpeed(); } Note: Other methods and properties (e.g. PushBrake(), PushGas(), SetWheelPosition() ) omitted for clarity This works well; you don't know how my object implem...
I have a simple C++ base class, derived class example. // Base.hpp #pragma once class Base { public: virtual float getData(); virtual void setData(float a, float b); virtual void setData(float d); protected: float data; }; //Base.cpp #include "stdafx.h" #include "Base.hpp" float Base::getData() { return data; ...
Let's say I have a FooClass with a bar() method. Inside of the bar() method, is there any way to tell if it's being called statically or not, so I can treat these two cases differently? FooClass::bar(); $baz = new FooClass(); $baz->bar(); ...
Say I am calling a third-party API which returns a Post, and I want to take that and transfer properties from it into my own Post class. I have in the past had a method like public static my.Post build(their.Post post) which maps the properties how I want. However, is it better/valid to have a constructor that accepts their.Post and doe...
Let's say you have a website that lets you build an account with up to three different account owners. Each entry page for the owner is a separate aspx page. The first person has very different business rules than the second and third owners. The first will have more fields as well and different ones will be required for them but not f...
I'm helping a professor for some lectures in OO and numerical algorithm in particular problem like to find the root of a function, minimization, interpolation, ... the problem is that he wants to teach at the same time OO with C++. I think that usual algorithms like these are implemented using procedural programming, at least you can use...
I often seem to run into the discussion of whether or not to apply some sort of prefix/suffix convention to interface type names, typically adding "I" to the beginning of the name. Personally I'm in the camp that advocates no prefix, but that's not what this question is about. Rather, it's about one of the arguments I often hear in that...
Edit: I've gotten a couple of answers that say what I already said in the question. What I am really interested in is finding corroborating reference material. I am looking at a code sample that more or less follows this pattern: Map<String, List> getListsFromTheDB() { Map<String, List> lists = new HashMap<String, List>(); //eac...