oop

professional usage of abstract class for translation

the code below is not giving me the answer i want, i don't know where is the problem? FR is the translation of EN (exactly like .properties file) i want to read the translation from the FR.java file if i want to reach the hello variable of fr.java or en.java from the index.jsp page. but code i wrote gives me the value from Lang.java St...

Design pattern for an email notification service which monitors workflow/state

I'm sorry this question is going to be a bit vague because I'm not entirely sure what I'm looking for. Basically in my (Asp.net MVC) web app I have some basic (manually coded) workflow triggered by my various user inputs. I need to send email configurable notifications when certain events happen. For example, there is an update status...

When to use which pattern?

Hello, As a junior developper, i'm a bit confused about some design patterns. Sometimes, i just don't know which to use in which context. For exemple, on creational patterns, i don't really know when to use: Factory Prototype Builder Actually, i see some differences; but i also see that you can use multiple solutions like: Callin...

Instantiate and call a method in one line

Is there a way to instantiate a class and call one of its methods in one line? I hoped the following would work but it doesn't: (new User())->get_name(); ...

An Exercise on parallel programming and object oriented design

Hi, I am trying to self-study both object oriented design and parallel programming using the following books: "agile software development" by Robert C. Martin Bruce Eckel's "Thinking in Patterns with Java" "The Art of Multiprocessor Programming" Maurice Herlihy "Programming Massively Parallel Processors" by David B. Kirk But to prac...

PHP, Fatal error: Call to undefined method, why?

Hi, I have a simple php structures. class Ingredient and class Ingredients, i have this code: class Ingredient { public function objectIsValid() { return $validate[0]; } } class Ingredients { public $ingObject; function __construct(){ $ingObject = new Ingredient(); } public function validateData() ...

Context on facebook api callback?

Is there a way to pass context in a javascript facebook sdk api callback? Here's a simple exemple. Now this won't work because the variable 'this.name' in my callback function would be undefined, because it's not in my user object context. Any idea how to do it? function user(id) { this.id = id; this.getUserName = function(fields,ca...

Name of locking design pattern (the one with `internal' methods)

I recall a design pattern for handling locking issues in C++ (where some locks are not re-entrant) by separating methods into 'external' and 'internal' ones. External ones acquire locks and can call internal ones which in turn assert that locks are held. External ones cannot call other external ones (because that would deadlock) and for ...

Trying to pass an array from one class to another

Hi, I'm new to OOP and i'm trying to get a grasp on it. What i'm trying to do is return all of the data in the table. There is only 2 rows right now, but i'm not sure how to put all the data in an array and then return it all the way back to the $results variable. Please help. <?php include('dates.php'); $events = new dates(); echo...

Designing my domain model around one 3rd-party library

Hi all, I'm working on a poker analysis tool with the following use case: User create Strategy class with one method: input GameState, output PokerAction User runs Analysis script, which launches a PokerGame between various Strategy subclasses (i.e. various strategies) PokerGame generates random deck PokerGame sends GameState to Strat...

Looking for a way to hide a class' base class

I'm building a library where I've got a pattern like the following: public class Foo : Foo_Impl { } public class Foo_Impl { } I don't want other developers to accidentally use the Foo_Impl class. What options are available to me to hide this? I'd also like to hide it from other classes in the same assembly it's defined in. Ideally...

Objective-c: Objects by value / Structs with methods / How can I get something like that?

I'm starting to code in objective-c and I've just realized that objects can only be passed by reference. What if I need an object to use static memory by default and to be copied instead of referenced? For example, I have an object Color with 3 int components r, g and b. I dont want these objects to be in dynamic memory and referenced ...

Object Oriented Language

Hi I am new to C#. I know all the object oriened language concepts theoretically. But I dont know where and when to use (abstraction , Interface ,Polymorphism , overriding, overloading, Encapsulation) concepts. I want to know what are advantages..like what is use of overloading. Method with same name but diiferent parameters.., we can ...

Can anyone explain how this works?

Ok, I have been browsing some php source code and need to know how the following class and sub methods use works: <?php $me = new Person; $me->name("Franky")->surname("Chanyau")->phone("+22", "456 789"); ?> I have pretty solid knowledge of OOP so I don't want a 101. I just need to know how to make the above code possible. Cheers Fra...

Use of polymorphism when generating web pages?

This is an example of a type of problem I have been having. When a user comes to the home page of my app there are two possibilities, he/she is: logged in not logged in If the user is logged in I want to display the username in the top right and a link which says "logout". If the user is not logged in I want to display a link which...

Is Inheritance the correct approach.

We have a base TCP Server class which provides Server functionallity. Now we want to provided secure TCP Server functionality as well. There were two approaches we were debating on. Pass a value to TCP server constructor, indication whether it should act as TCPServer or TCP secure server. Create a TCPSecure class inheriting from TCP Se...

Multiple inheritance in javascript

Here's some question about oop in js (questions in the code below). <html> <script> function A(){ a = 'a - private FROM A()'; this.a = 'a - public FROM A()'; this.get_a = function(){ return a; } } function B(){ this.b = 'b - private FROM B()'; this.a = 'a - public FROM B() '; ...

Exception instead Notice

Hello, I have two classes: class Test { public $name; } /*******/ class MyClass { private $_test = NULL; __get($name) { return $this->$name; } __set($name,$value) { $this->$name = $value; } } And when I want to use it this way: $obj1 = new MyClass(); $obj1->_test = new Test(); $obj1->_test->name = 'Test!'...

How to create OOP Class in Javascript

I'm hesitant to use just any tutorial because I know how those tutorials can end up being, teaching you bad ways to do things. I want to setup a class in Javascript, so that I can just do var vehicle = new Vehicle(el); var model = vehicle->getModel(); These functions would read the HTML and get and manage the elements on the page. I...

How to prevent inheritance for some methods?!

Hi How can I prevent inheritance of some methods or properties in derived classes?! public class BaseClass : Collection { //Some operations... //Should not let derived classes inherit 'Add' method. } public class DerivedClass : BaseClass { public void DoSomething(int Item) { ...