oop

How should I arrange my projects/classes in .NET to avoid circular dependecies.

My program is attempting to draw grammars in C# & WPF. I have: 1 DataStructure project which describes a tree structure of how it should be visualised. Each node in the tree relates to a symbol in the grammar. Nodes at the top define the rule for that nonterminal symbol. 1 Drawer project which describes the user controls in WPF. I nee...

What is the difference between object-oriented langauges and non object-oriented languages?

I am new to programing and I have been hearing a lot about how C is a non-object-oriented language and how java is an object-oriented language I was wondering what the difference was? Thank you. ...

How to generate entities to database

I create a linq to sql class Create all entities that i need for my app Now i need to create this entities in the database is there a way to generate all of my entities? yes i want to generate tables for the entities ...

adding const before the brackets in c++

Hi, Just wondering why the syntax for virtual functions uses a const before the curly braces, as below: virtual void print(int chw, int dus) const; Incidentally, the code doesnt seem to work without the const, which is interesting.. not sure why? many thanks! ...

Problem with FluentNhbernate Mapping

Hi, I am new to all the OOP and ORM stuff, so i would appreciate your help... I have a Team Class: public class Team : IEntity<Team> { public virtual int ID { get; private set; } public virtual string Code{ get; private set; } public virtual TeamWorker TeamLeader { get; private set; } public virtual IEnumerable<TeamW...

C#: Resolving Invalid Cast Exception Between an Inherited Class and Its Base

I have two classes, named Post and Question. Question is defined as: public class Question : Post { //... } My Question class does not override any members of Post, it just expresses a few other ones. What I want to accomplish I have an object of type Post, whose members are populated. Now, I want to convert it into a Question, so...

Comparing two inherited objects Ruby

Hi, I have a base class which contains an equal? method. I've then inherited that object and want to use the equal? method in the super class as part of the equal? method in the sub class. class A @a @b def equal?(in) if(@a == in.a && @b == in.b) true else false end end ...

calling member function without object error: C++ / (G++) oop

Hi, i was curious to know why the following throws an error in g++ (cannot call member function without object). I suppose a workaround would be to have the B class variable as static variable in A - but i was curious to find out why, when there is an instance of A's child class C created, this still throws an error - many thanks! #inc...

How can I use a class made in PHP?

I have a ready made PHP class. Now how can I use that class or implement it in my page. How would I go about doing this? ...

[C++] Why shall I use "using" keyword to access my base class method?

I wrote the code below in order to explain my issue. If I comment the line 11 (with the keyword "using"), the compiler does not compile the file and display this error: invalid conversion from 'char' to 'const char*'. It seems to do not see the method void action(char) of Parent class in Son class. Why the compiler behaves this way? Or h...

Why are circular dependencies considered harmful?

Why is it a bad design for an object to refer to another object that refers back to the first one? ...

Object Oriented Design approach to a conversion app

I think i might be being blinded by the way I've learned OO principles. Its always taught in the manner of tangible object is a descendant of another tangible object. Anyway... I'm trying to work out an OO approach to a conversion utility, basically it will read a text file and based on the first word(s) on the line it will go off and t...

Has-A relationship applies to inherited members?

Given the code: class Car{ Engine engine; } class SportCar extends Car{ SportChair chair; } Is it valid to say that 'SportCar "has-a" Engine and a SportChair'? Or the only valid affirmations are: 'SportCar "has-a" SportChair' and 'Car "has-a" Engine' ? ...

How can I improve my Object Oriented Programming?

I understand procedural programming (well, who doesnt) and want to get a good understanding of OOP and after that functional. I'm just a hobbiest so it will take me an age and a day, but its fun. Does anyone have any ideas for what I can do to help? Project ideas? Example well documented code thats out their? I am currently using C++ b...

ServiceLocator and the Open/Closed Principle

I'd like to: Make commonly required services visible to all classes that need them, with a minimum of boilerplate, and without sacrificing testability! It's a small project and I think DI might be overkill, but maybe I'm wrong? Anyhow, I have been focusing on the ServiceLocator pattern as described by Martin Fowler In a client clas...

PHP[OOP] - How to call class constructor manually?

Please see the code bellow: 01. class Test { 02. public function __construct($param1, $param2, $param3) { 03. echo $param1.$param2.$param3; 04. } 05. } 06. 07. $params = array('p1','p2','p3'); 08. 09. $ob = new Test; 10. 11. if(method_exists($ob,'__construct')) { 12. call_user_func_array(array($ob,'__construct'),$...

PHP OOP Design for simple Models

Hi, i've a little problem with the proper design for some simple database models. Lets say i have an User Object with getter/setters and an read method. Read querys the database and sets the properties. class User extends MyDbBaseClass { protected $_id; protected $_name; public function setId($id) { $this->_id = $id; } public funct...

PHP [OOP] : Memory allocation for Inheritance

Please see the code bellow: class A { public x = 5; public y = 6; public z = 7; } class B extends A { public m = 1; public n = 2; } $a = new A(); $b = new B() From the above code let $a is allocating x amount of memory and $b is allocating y amount of memory; Now my question is which one is correct from bellow? ...

Two methods that differ only in LINQ where part - delegate?

I have a method: internal List<int> GetOldDoctorsIDs { var Result = from DataRow doctor in DoctorTable.Rows where doctor.Age > 30 select doctor.ID List<int> Doctors = new List<int>(); foreach (int id in Result) { //Register getting data Database.LogAccess("GetOldDoctors...

Is this a sane implementation of constructor injection?

Following on from my question on service locators I have decided to use constructor injection instead. Please consider the following code: <?php interface IAppServiceRegistry { public function getDb(); public function getLogger(); } interface IFooServiceRegistry extends IAppServiceRegistry { public...