abstraction

Clean Code: Should Objects have public properties?

I'm reading the book "Clean Code" and am struggling with a concept. When discussing Objects and Data Structures, it states the following: Objects hide their data behind abstractions and expose functions that operate on that data. Data Structures expose their data and have no meaningful functions. So, what I'm getting from this is th...

Any easy illustration to get the idea of abstraction?

How would you help a newbie to grasp the idea of abstraction? Anybody know a suitable illustration? ...

Loose coupling of static stuff

I have a class, ClassA that uses a client I wrote to send text messages, TextClient, to send some text messages via a call to the static method TextClient.Send(string text, string destination) // where destination is a phone number However, I also have a mail client class, MailClient, which sends emails with the same signature: MailC...

difference between encapsulation and abstraction concepts

Hello everyone, Please can somebody explain to me the main differences between the principles of encapsulation and abstraction in objected-oriented programming (if possible with examples). Thanks in advance. ...

PHP5 & Abstract Classes. Separate copy of class variables for each child class?

Let's see if I can describe this properly... I have an abstract class that when other classes extend from it, I'd like for the abstract class' data to be reset to zero. The idea being that I have a pile of classes extending this and using MySQL table's for data structure. I don't want to query the DB with every class instantiation to d...

State monads: trading one pattern for another?

So I'm writing a game in Haskell, and I'm expressing a player's turn as a series of state-altering functions that correlate to various turn phases. Originally, this looks something like: let game' = phase1 game game'' = phase2 game' -- etc. Prime candidate for State monadosity, right? This leads to the more elegant: do phase1 ...

Utilizing UI abstraction

When utilizing a UI abstraction, then the data you're displaying is protected from implementation changes in the UI layer. Does/should/can this extend to higher-level things, like for example, display as a tree or a grid? I can't work out how to insulate the abstraction from the higher-level details of how the UI is going to display the ...

How to make these 2 blocks of almost identical code reusable?

I need advice on what I need to do to make the following two blocks of code reusable. I have to produce another table of funds and while I'm doing that, I'd like to create FundsTable.ascx partial view that all Views that need to display a fund table can use. // Inherits="System.Web.Mvc.ViewPage<CompanyViewModel> // this is a company <%f...

Where should I place text that I'm trying to abstract in my CakePHP application?

I am writing a CakePHP application and am trying to have text that is frequently displayed (or particularly long) saved in a config file somewhere that we can easily edit it. Where should i put this file and how do I access it? I am also worried about the tradeoff in speed of reading this file when we need to display text, as well as loc...

Would having x number of UPDATE queries in a MySQL transaction be worse or about the same as putting them into one UPDATE query?

This may be a silly question with an obvious answer, but I've pondered it for quite some time and can't really come up with a good answer on my own. I'm working on a telecommunications website and I've made a mapper framework and query builder of which I'm rather proud. The mapper has a set function (generates an UPDATE query) to update...

Enumset wrapper for AbstractActions

I'd like to load a series of Swing Actions into a container at runtime and access them by a constant name as is possible with an Enum. The purpose of this would be to both restrict the Actions possible and also improve readability. Initially, I was considering a sort of dynamic enum (see http://blog.xebia.com/2009/04/02/dynamic-enums-in...

Abstraction or Inheritance use case?

Hi I'm modeling a UDP communication server in VisualBasic.NET. In my system I have 3 types of messages: basic, advanced and full messages. Basic message is composed of: ID, Version and Serial Number. Advanced message is composed of: basic message + NSeq, IDMsg, Size and CRC. Full message is composed of: advanced message + Timestamp. E...

How should I restructure a large Perl script?

Hi there. I have a more or less large Perl script of ~ 1000 lines. The script accepts a few arguments and it runs straight forward. No modules, no functions. The script could be divided into three parts, initialization part, arguments parsing part and work part, but I don't know how to do that. Everything must be kept in a single file. P...

Best Practice to abstract ActiveRecord model queries in Rails?

I'd like to extract out logic from the controllers to somewhere that it can be more DRY. What's the best way of handling something like the following in Rails? For instance, as opposed to having the query in the controllers, I could place it in the model: class SmoothieBlender < ActiveRecord::Base belongs_to :user def self.get_...

Is using views for everything a crazy idea?

I'm working on building a MySQL database and I'm thinking that rather than encode a bunch of complex join queries in the front end I'll create a view for any queries I need and then have all the front end code do simple SELECT whatever FROM some_view WHERE something=5; queries. It seems like a great idea as it abstracts away the underl...

Should unit tests know about NHibernate?

I'm following on from a previous question. The answer I accepted involves using a generic IRepository to handle basic CRUD, wrapped with a domain specific IMovieRepository which delegates to the generic setup. A further detail involves having a WrapQueryInSession method on the generic IRepository: IEnumerable<T> WrapQueryInSession(Func<...

How to get the name of the calling class (in PHP).

define('anActionType', 1); $actionTypes = array(anActionType => 'anActionType'); class core { public $callbacks = array(); public $plugins = array(); public function __construct() { $this->plugins[] = new admin(); $this->plugins[] = new client(); } } abstract class plugin { public function registerCall...

what is data abstraction exactly means

Hi all, what is data abstraction means? can i get some sample examples as well as real time examples in our daily life ...

OpenGL DirectX "Abstraction Layer"

Hey guys, I was reading about creating abstraction layers to make it easy to switch between platforms. They did not go into much detail but here is what I got out if it. Is it just something like this? void pushMatrix(){ if (directx){ // do directx function }else if (opengl){ // do opengl function } } Is this how it ...

How to identify that code is over abstracted?

Hi All What should be the measures that should be used to identify that code is over abstracted and very hard to understand and what should be done to reduce over abstraction? ...