oop

What does the 'static' keyword do in Java?

To be specific, I was trying this code: package hello; public class Hello { Clock clock = new Clock(); public static void main(String args[]) { clock.sayTime(); } } But it gave an error like 'Cannot access non-static field in static method main'. So I changed the declaration of clock to this: static Clock clock ...

Variable naming conventions in Java?

In PHP, we (at least the good programmers) always start general variable names with a lower-case letter, but class variables/objects with an upper-case letter to distinguish them. In the same way we start general file names with a lower case letter, but files containing Classes with an upper case letter. E.g: <?php $number=123; $string...

.NET Class Refactoring Dilemma

So I'm refactoring a legacy codebase I've inherited, and in the process I found a static class that encapsulates the logic for launching 3rd party applications. It essentially looks like this (shortened for brevity to only show one application): using System.IO; using System.Configuration; public static class ExternalApplications { ...

Object-Orientation in C

Can someone please share a set of nifty preprocessor hacks (ANSI C89/ISO C90 compatible please) which enable some kind of ugly (but usable) object-orientation in C? I am familiar with a few different object-oriented languages, so please don't respond with answers like "Learn C++!". I have read "Object-Oriented Programming With ANSI C" (b...

Examples of 'Things' that are not Objects in Ruby

"Everything is an object" was one of the first things I learned about Ruby, but in Peter Cooper's Beginning Ruby: From Novice to Professional book, it is mentioned that "almost everything in Ruby is an object". Can you give me some examples of things that are not objects in Ruby? ...

Java Interfaces?

I really need help with interfaces in general... Any resources that you guys would recommend me? Related: How are Java interfaces actually used? Java interface and inheritance Java Interface Usage Guidelines — Are getters and setters in an interface bad? Why can’t I define a static method in a Java interface? ...

One UITableView - Multiple DataSource, best design pattern?

This seems like a typical problem, but I have a UITableView that has identical behavior for two separate data sources. What is the best way of going about designing the class hierarchy to have as little duplication and if/else conditions? The view controller is going to do the same exact thing to both data sources, they're just unique in...

Design Question - Storing Images as Objects.

Ok, so my site is centric to a lot of dynamic user entered images for different user defined objects throughout. So I have many objects, and those objects have images. Is it good practice to treat images like an object since the "Image Name" and "Image Bytes" columns are repeated many times? Or is it more sensible just to include those...

PHP classes: Need help to inherit two classes

I need help in designing my PHP classes where I need to extend from multiple classes. I have a general class, Pagination.php that does all sort of pagination and sorting. All other classes will use this for pagination. To make my life easier, I made a class generator that generates a class from MySQL table. All the properties, getters,...

Best to use Private methods or Protected methods?

In a lot of my PHP projects, I end up with classes that have non-public functions that I don't intend to extend. Is it best to declare these as protected, or private? I can see arguments both ways - making them private is a far more conservative approach, but it can be argued that they could be made protected later if I want the method...

Calling a private instance method from a class method in Ruby.

Can I create a private instance method that can be called by a class method? class Foo def initialize(n) @n = n end private # or protected? def plus(n) @n += n end end class Foo def Foo.bar(my_instance, n) my_instance.plus(n) end end a = Foo.new(5) a.plus(3) # This should not be allowed, but Foo.bar(a, 3) # I...

Is there a simple way to emulate Objective-C Categories in C#?

I have a weird design situation that I've never encountered before... If I were using Objective-C, I would solve it with categories, but I have to use C# 2.0. First, some background. I have two abstraction layers in this class library. The bottom layer implements a plug-in architecture for components that scan content (sorry, can't be m...

Inherited Public Properties not showing up in Intellisense

I have inherited a class in vb.net and when I create the object, I am only seeing one of the inherited public properties in intellisense. Any solution to this problem? print("Public Class CompanyMailMessage Inherits MailMessage Private AdobeDisclaimer As String = "You will need Adobe Acrobat to read this file. If it is not ins...

How do you use Intefaces with the Factory Pattern in Domain-Driven Design?

Does it make sense to use interfaces for your domain object factories by default, or should interfaces be reserved for the factory classes only when you need them? public IUserFactory { User CreateNewUser(); } public UserFactory : IUserFactory { public User CreateNewUser() { return new User(); } } ...

Dynamically Create Subclass

I am using Kohana and just found this piece of code in their autoloading method // Class extension to be evaluated $extension = 'class '.$class.' extends '.$class.'_Core { }'; // Start class analysis $core = new ReflectionClass($class.'_Core'); if ($core->isAbstract()) { // Make the extension abstract $extension = 'a...

When I extend an MX class in Flex, how do I reference it in the MXML?

Meaning, if I have: <mx:Tree> <!-- ... --> </mx:Tree> and I want to change some of the control's behaviour or add functionality, by doing (in AS): class ChristmasTree extends mx.controls.Tree { // ... } how do I change the MXML so that my class is used? In the manual it says how to extend components via MXML, but how do I ...

Can you use a object-database in a production system?

Object-databases are used very seldomly, albeit they offer a way to live without SQL, which is, I think, a benefit of its own. Yet, I have seen them about never in production systems. Is there something fundamentally wrong with object-databases? Can I use a object-database in a production system? Edit: So, maybe I should confess that ...

Why are constructors not inherited?

I'm guessing there's something really basic about C# inheritance that I don't understand. Would someone please enlighten me? ...

How does object reuse work in .NET?

I've recently moved from VB6 to VB.NET and I am finally getting there with understanding the inner workings. I've been looking at my company's existing codebase and I am a little suprised. I understand that when VB.NET creates a string it see's if the string is in memory and if not creates a new instance of that string, otherwise it po...

What is the best analogy to help non-oop developers grok interface based programming?

I'm having a hard time trying to get my team comfortable with interface based programming ... anyone have some suggestions? ...