oop

overloading constructors and reusing code

Let's say I've got an object Customer with a couple properties (ID, FirstName, LastName). I've got the default constructor Customer(), but then I've also got a Customer(DataRow dr), since I load this object from a database and that's a simple way to do it. I frequently come to a point where I want to set up another constructor, Custome...

MustOverride Properties with mixed access level Get / Set

Visual Basic allows for properties with mixed access levels, for example Public Property Name() as String Get End Get Friend Set(ByVal value As String) End Set End Property Is there a way to define a MustOverride property with mixed getter/setter access level? ...

For learning OO, do you recommend Head First Java or Head First OOA&D?

I learned some C on my own and I've finished one semester of Java programming. OO programming takes a different approach to problems. I want to know which book will help me pick up the OO aspects of Java. So I've looked through Stack Overflow and two books have come up several times: Head First Java and Head First Object Oriented Anal...

Private method naming convention

Is there a convention for naming the private method that I have called "_Add" here? I am not a fan of the leading underscore but it is what one of my teammates suggests. public Vector Add(Vector vector) { // check vector for null, and compare Length to vector.Length return _Add(vector); } public static Vector Add(Vector vector1...

What does it mean to "program to an interface"?

Hi, I have seen this mentioned a few times and I am not totally clear on what it means. When and why would you do this? I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly. Is it just so if you were to do: IInterface classRef = new ObjectWhatever() You could use ...

Using Objects across methods

Edit again: I think I get it now. All I need to do then is use the current class colon the class I want to be able to access? Person : Student, or person : teacher Is that correct? Thank everyone for the help, I really appreciate it. This will help me learn what is OO and what is not. I really appreciate that. I'm currently ...

What are the different types of encapsulation?

This question came from the worst interview questions thread here So, what are the different types of encapsulation? Am I right in thinking this basically refers to central OO concepts such as Abstraction, Polymorphism and Inheritance? My understanding of encapsulation is that it is a method of hiding data / functionality, but I never...

Prototype based object orientation. The good, the bad and the ugly?

Hello, I come from classes object orientation languages and recently I have been learning those fancy dynamic languages (JavaScript, Python and Lua) and I want some tips about how to use OO in those languages. It would be useful to know the pitfalls and the shortcomings of such approach and the advantages compared to traditional OO. The...

Dispatching exceptions in C++

How should exceptions be dispatched so that error handling and diagnostics can be handled in a centralized, user-friendly manner? For example: A DataHW class handles communication with some data acquisition hardware. The DataHW class may throw exceptions based on a number of possible errors: intermittent signal, no signal, CRC failure...

What's the best way to define a class in javascript

While I'm not entirely new to javascript I have very little knowledge when it comes to best practices. In particular, I prefer to use OOP in large scale projects like the one I'm working on right now. I need to create several classes in javascript but, if I'm not mistaken, there are at least a couple of ways to go about doing that. Can...

What's wrong with Copy Constructors? Why use Cloneable interface?

When programming C++ we used to create copy constructors when needed (or so we were taught). When switching to Java a few years ago, I noticed that the Cloneable interface is now being used instead. C# followed the same route defining the ICloneable interface. It seems to me that cloning is part of the definition of OOP. But I wonder, wh...

Parsing files to set data of an object - a design question

I recently had to write some code which parsed a file to set data in an object. As there were several objects and corresponding files involved here, I decided to separate the parsing code out. So I then had one class for parsing the files, CommandFileParser, and two classes per file/object type: one for the actual object itself and one ...

What is the best solution to do Reporting on Object data for .NET ?

Hi, Our projects are using objects as the data source to reports. Our business layer is returning single objects or IEnumerable. Our reports (quite complex) need to display value-type properties of the object, and its related objects. Typical case would be, from a List, display a master report with category data, then a subreport with ...

Locking class members in PHP

In PHP, if you define a class, and then instantiate an object of that class, it's possible to later arbitrarily add new members to that class. For example: class foo { public $bar = 5; } $A = new foo; $A->temp = 10; However, I'd like the ability to make it impossible to add new members this way. Basically I want the class to ON...

What is the difference between abstract function and virtual function ?

Which is the more correct approach? In which cases is it recommended to use virtual or abstract? ...

Is every abstract function virtual in c#, in general?

I was looking at this question and I was wondering whether every abstract function should be considered to be a virtual function in C# or in general? I was a bit puzzled by the "you must override/you may override" responses to that question. Not being a C# programmer, I tend to think that abstract functions are a compile-time concept on...

Do any other developers get yelled at for making every thing public?

I am sick and tired of getting yelled at when I make all my variables in a Java class public, for the sake of not needing to write five times more code for getters and setters. Do others share this problem? ...

Description of what an Interface does?

Duplicate: http://stackoverflow.com/questions/122883/interfaces-why-cant-i-seem-to-grasp-them With regards to OOP,how would you describe an interface? What i mean is , sub-classing can be described as "Has-A" and Inheritance could be "Is-A". A member method could be "Can-Do" .. Is there any way this could be extended (no pun intended)...

Trying to design an object model - using enums

I am trying to design an object model (for C#), and can't work out the best way to store the data. I'll try to use a simple example to illustrate this! I have an object "pet", which could be one of, "cat", "dog" etc. So I have created an "pet" class with a "petType" enum to store this. Now this is where it gets tricky. If an "pet" is a...

Obj C - Understanding pointers...

I'm having a hell of a time understanding pointers in Objective C. They don't behave like I would assume based on various C tutorials. Example: // Define Name and ID NSString *processName = [[NSProcessInfo processInfo] processName]; NSNumber *processID = [NSNumber numberWithInt:[[NSProcessInfo processInfo] processIdentifier]]; // Prin...