Sunday, March 31, 2024

বিল্ডার

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Builder: এটি object এর গঠনকে তার প্রতিনিধিত্ব থেকে আলাদা করে। সাধারণত object যদি complex হয়ে থাকে তবে সেটির creation এর ভার দেয়া হয় অন্য আরেকটি class/interfaceকে যা Builder নামে পরিচিত।এতে creation এর দরকারি methods থাকে। Concrete Builder এটিকে implement এর কাজ করে থাকে আর object এর বিভিন্ন রুপের গঠন প্রক্রিয়ার সাথে জড়িত । আরেকটি class থাকে যা Director নামে পরিচিত যা মূলত: object এর গঠন কাজকে তদারক করে থাকে Builder object এর সাহায্যে। উদাহরণে Lamp গঠন প্রক্রিয়াকে তুলে ধরা হয়েছে। এখানে BedLampBuilder class টি Bed Lamp গঠন করছে আর Director তা তদারক করছে। buildStand() আর buildShade() methods ঠিক করছে Lamp এর Stand আর Shade কি ধরণের হবে। Director এর constructor এ তিনটি argument দেয়া হয়েছে : একটি Builder object আর দু'টি হল user এর সরবরাহ করা string arguments, যা Stand আর Shade কিরকম হবে তা বলে দিচ্ছে।

উদাহরণ:
class Lamp{
constructor(){
this.l=" ";
this.s=" ";
}
Stand(t){this.l=t;}
Shade(s){this.s=s;}
des(){document.write(this.l+ ", "+this.s);}
}
class Builder{
constructor(){}
buildShade(s){}
buildStand(t){}
getLamp(){}
}
class BedLampBuilder extends Builder{
w=null;
constructor(){
super();
var q=new Lamp ();
this.w=q;
}
buildStand(t){this.w.Stand(t);}
buildShade(s){ this.w.Shade(s);}
getLamp(){return this.w;}
}
class Director{
constructor(b,s,c){
this.b=b;
this.b.buildStand(s);
this.b.buildShade(c);
}
getL(){
var a=this.b.getLamp();
return a;
}
}
var d=new Director(new BedLampBuilder(),"Black Stand","Yellow Shade");
d.getL().des();

চেষ্টা করা যাক:Progrgram টি আবার লিখি। এবার Table Lamp এর জন্য।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Saturday, March 30, 2024

Will Tax On Remittances Lower The Inward Flow?


Idea of taxing the remitter
May bring change for the better.

Recently, IMF proposed to impose tax on remittances. The suggestion came at a moment when the country is facing severe revenue shortfall. This year NBR's revenue target is Taka 4.3 trillion, but NBR so far achieved Taka 1.65 trillion. In the first six months of current fiscal year, there is a revenue shortfall of Taka 232.27 billion. This tells how acute the financing crisis has become.

But the idea of taxing remittances is not greeted very well. Strongest argument put forward against it is the loss of remittances. Many migrant Bangladeshi workers may feel discouraged to remit money back home,opponents of the suggestion argued.

However, if we look at the Value Added Tax(VAT) revenue ,then the argument sounds hollow. Imposition of VAT did not welcome by all the quarters at the initial stage. But gradually it has become the biggest revenue earning source of the government. When initiated, it merely fetched crores of Taka in 1991. But in 2023,it fetched Taka 1.25 lakh crore. VAT's share of revenue earning increased at a remarkable pace. Now government depends less on foreign financing of the budget.

Similarly, import duty accounts for a bigger percentage of revenue earning. Duty on imports never curbed the growth of imports.Govt collected a total revenue of Taka 32,125 crores from import duties till February of 2024,registering around 11% growth. This has achieved in spite of the fact that government introduced several import restrictions in the wake of dollar crisis.

Like VAT and import duty, imposition of duty on remittances will not result in loss of remittances. A 5% tax on $20 billion worth of remittances will annually fetch around $1 billion or Taka 115 billion, ample to cover half of the revenue shortfall incurred in the first six months of this fiscal year. Part of the money will finance the incentives given to remittances repatriated to home. Universal applicability of this tax rather than to a target group will pave the path for its success. Since every remitter has to pay this tax, very few may opt for alternative channel. Government is in dubious mood about introducing such tax, fearing further increase in revenue shortfall. I think,and pretty convinced, that such measure will increase the government coffer in this troubling time. More early NBR could implement it, better improvement it may expect in revenue collection. So far NBR has not managed to get enough revenue from the traditional sources to meet its revenue goal. Giving a go to the idea of taxing the remitter may become handy.

Thursday, March 28, 2024

প্রোটোটাইপ

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Prototype: এটি Creational Design Pattern দলের। এর মাধ্যমে আনকোড়া নতুন object তৈরির বদলে আগে থেকে বিদ্যমান object এর copy তৈরি করা হয়। আর copy করার কাজটি করা হয় clone() এর সাহায্যে। যখন নতুন object তৈরি করা বেশ সময় সাপেক্ষ তখন এই pattern বেশ কাজে দেয়।Subclass নির্ভরতা কমিয়ে নতুন behavior যোগ করতে এবং runtime এ প্রয়োজন অনুযায়ি object তৈরি করতে এই pattern বেশ কাজে দেয়। উদাহরণে Cycle তৈরির জন্য যেসব Parts এর দরকার হয় তার Prototype আগে থেকে তৈরি করে রেখে একেবারে runtime এ Cycle object তৈরির সময় এদেরকে ব্যবহার করা হয়েছে। এখানে Parts হচ্ছে Prototype interface আর Cycle, Wheel,Frame ও BackSeat হচ্ছে এর implementation । এদের সবার clone() নামক method আছে যা ঐ class এর instance/object তৈরি করে return করছে। Cycle class এ addWheel(),addFrame() ও addBackSeat() নামক method গুলো ঐ objectকে জুড়ে দেবার কাজ করছে। CycleFact হল Cycle object assemble করার interface আর ProtoFact হচ্ছে এর implementation। ProtoFact এর method গুলোর (getWheel(),getFrame() ইত্যাদি) মাধ্যমে যেসব objects কে ProtoFact এ argument হিসেবে pass করা হয়েছিল তাদেরকে clone() করে copy করা হচ্ছে ।Cycle আমরা কেমন চাই-- Back seat সহ না Back seat ছাড়া --তার উপর নির্ভর করে আমরা runtimeএ প্রয়োজন অনুযায়ি argument দিতে পারি ProtoFact এ। এজন্য ProtoFact এ দু'ধরণের constructor রয়েছে। Runtimeএ এটি না করলে আমাদের Factory method এর মত CycleWithBackSeat এবং CycleNoBackSeat নামে আলাদা subclass তৈরি করতে হত। এই Prototype pattern ব্যবহারের ফলে আমাদের Subclassing এর উপর বেশি নির্ভর করতে হচ্ছে না আর আমরা runtime এ দরকার অনুযায়ি object যোগ/বাদ দিতে পারছি। যেমন: BackSeat দরকার নেই বলে এর object আমরা runtime-এ ProtoFact এ argument হিসেবে দেইনি।উদাহরণে Back seat ছাড়া Cycle assemble করা হয়েছে।

উদাহরণ:
class Parts{
constructor(){}
clone(){}
des(){document.write("Parts");}
}
class Wheel extends Parts{
constructor(){super();}
clone(){return new Wheel(this);}
des(){document.write("Wheel");}
}
class Frame extends Parts{
constructor(){super();}
clone(){return new Frame(this);}
des(){document.write("Frame & seat");}
}
class BackSeat extends Parts{
constructor(){super();}
clone(){return new BackSeat(this);}
des(){document.write("Back seat");}
}
class Cycle extends Parts{
w=null;
f=null;
b=null;
constructor(){super();}
addWheel(w){this.w=w;}
addFrame(f){this.f=f;}
addBackSeat(b){this.b=b;}
clone(){return new Cycle(this);}
des(){document.write("Cycle:");
this.w.des();
this.f.des();
this.b.des();
}
}
class CycleFact{
constructor(){}
makeCycle(){ return new Cycle();}
getBackSeat(){return new BackSeat();}
getFrame(){return new Frame();}
getWheel(){return new Wheel();}
}
class ProtoFact extends CycleFact{
constructor(c,w,f,b){super();
this.c=c;this.w=w; this.f=f;this.b=b;}
static trio(c,w,f,b){
return new ProtoFact(c,w,f,null);
}
static whole(c,w,f,b){
return new ProtoFact(c,w,f,b);
}
makeCycle(){ return this.c.clone();}
getBackSeat(){return this.b.clone();}
getFrame(){return this.f.clone();}
getWheel(){return this.w.clone();}
}
var p=new ProtoFact(new Cycle (),new Wheel(),new Frame());
var a=p.makeCycle();
var w=p.getWheel();
var f=p.getFrame();
a.addWheel(w);
a.addFrame(f);
a.des();

চেষ্টা করা যাক:Progrgram টি আবার লিখি। এবার Cycle এ Back seat থাকবে। দরকারি পরিবর্তন যোগ করি।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Monday, March 25, 2024

La Semaine Dernière A Mes Yeux




(23 mars --- 29 mars)

Cliquez pour voir/cacher
Ma Semaine Gastronomique
Date Petit déjeuner/Début de jeûne Déjeuner Dîner Snacks,Sucreries,Boissons et Fritures/Fin de jeûne
23 Riz,Pomme de terre tchop,Œuf dur,Poisson latya,Pomme de terre ---- --- Pois chiches,Riz,Lait,Ruhi avec Pomme de terre
24 Riz,Pomme de terre avec Ruhi,Œuf dur --- --- Riz,Pois chiches,Lait,Ruhi
25 Riz,soupe aux lentilles,Ruhi,Latya poisson --- --- Riz,Pois chiches,Lait,Poulet,Pomme de terre
26 Riz,Œuf dur,Poulet,Pomme de terre --- --- Riz,Pois chiches,Lait
27 Riz,Poulet avec Pomme de terre --- --- Riz,Pois chiches,Petit poissons,Pomme de terre,Œuf dur
28 Riz,Petit poisson,Pomme de terre ---- --- Riz,Épinard d'eau,Pois chiches,Pomme de terre
29 Riz,Œuf dur,Koi poisson,Pomme de terre --- --- Riz,Pois chiches,gâteau traditionnel (Poa pitha)

Saturday, March 23, 2024

মেমেন্টো

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Memento:এটি objects এর ভেতরের অবস্থা প্রকাশ করে দেয়। object এর পূর্বের অবস্থা পুনরুদ্ধারে এই design pattern এর ব্যবহার করা হয়। এটি Behavioral Design Pattern দলের। এর প্রধান অংশ হচ্ছে:

  • Originator: যার ভেতরের অবস্থা আমাদের বিবেচনার বিষয়।
  • Caretaker:যে Originator এর উপর কাজ করে;তার ভেতরের পরিবর্তনকে পূর্বের অবস্থায় নিয়ে যেতে চায়।
  • Memento:এটি সাধারণ object; এর উপর Caretaker এর কোন প্রভাব নেই; নাম শুনেই বোঝা যাচ্ছে এটি অতীতের কোন জিনিস বা ঘটনাকে নির্দেশ করছে।
উদাহরণে Memento class B এর member হচ্ছে একটি integer এবং getInt() এর মাধ্যমে সেটি integerটিকে return করছে। Originator class A তার set() এর মাধ্যমে তার অবস্থা ঠিক করছে আর store() এর সাহায্যে তা Memento object এ রুপান্তর করছে আর getB() এর মাধ্যমে প্রযোজ্য Memento object এর integer কে প্রকাশ করে দিচ্ছে।Caretaker তার add() এর সাহায্যে Originator object এর রুপান্তর করা Memento object জমা করছে নিজের array তে। getState() এর মাধ্যমে user এর সরবরাহ করা index নিয়ে পূর্বের দরকারি Memento object কে পুনরুদ্ধার করছে।

উদাহরণ:
//memento
class B{
constructor(c){this.c=c;}
getInt(){ return this.c;}
}
//originator
class A{
constructor(){}
set(a){this.a=a;}
store(){
var b=new B(this.a);
return b;
}
getB(k){
this.a=k.getInt();
document.write(this.a);
}
}
//caretaker
class Caretaker {
constructor(){this.s=[];}
add(item){
this.s.push(item);
}
getState(ind){
return this.s[ind];
}
}
var c=new Caretaker ();
var a=new A();
a.set(2);
c.add(a.store());
a.set(3);
c.add(a.store());
a.set(4);
c.add(a.store());
a.getB(c.getState(2));

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Friday, March 22, 2024

First Commodity Exchange Sees The Light


Country launches first commodity exchange
Withering away uncertainties and ushering new change.

It is indeed a good news that country's first commodity exchange market is about to see the light. Bangladesh Stock Exchange and Commission(BSEC) has awarded Chittagong Stock Exchange (CSE) the licence to operate commodity exchange(For more read the news"CSE Gets Conditional License" by The Business Standard).Metals,agricultural commodities and hydrocarbons will be traded here at negotiated price. It will pave the path for trading futures contracts that are agreements made today to be completed at a future date. Bangladesh will be the fourth country in the subcontinent to operate commodity exchange market after India,Pakistan and Nepal.

My guess is that initially gold,coal,crude oil,LNG,rice,tea,sugar,wheat,edible oil,pulses,flower etc will be traded.Big traders cum importers,rice dealers,captive power plants, consumer goods company, super shops,posh restaurants and hotels,e-commerce platforms,banks and individual investors will be benefitted tremendously from the introduction of commodity exchange market. Banks and individual investors will see new areas of investment and unlike the stock market, the market will be opened till the midnight, ensuring trading and business activities almost an entire day. Super shops and e-commerce platforms will have better bargaining possibility with the suppliers and will see their profit margin improve significantly. Consumer goods companies and hotels will procure ingredients at negotiated prices, alleviating the uncertainties.

Commodity market is pretty volatile. Recently we have witnessed how sky rocketing prices in kitchen market squeezed the pockets of consumers from all walks of life. Unpredictability of kitchen items caused a great deal of unease among the consumers, policy planners and the true businessmen. To figure out the future market price is increasingly difficult in the context of Bangladesh. Commodity exchange market to some extent allows predictability over the prices of commodities that matter to us. The prices of commodities will be documented in the futures contracts. And markets will get information about the price based on the volume of trading of the futures contracts at the exchange. Moreover,such formal arrangement of commodity trading will draw more traders and new entrants into the commodity market. And thanks to spread of information, consumers will get regular information/update about the future prices of the commodities,which they currently do not avail.

While awarding the contract, BSEC laid down that a consumer good company had to sell its share of a brokerage firm that holds share of CSE. BSEC in this case differentiated between the interests of regulator and those of key player. But we often see producer/importer of intermediate goods also holds significant market share of the final good. In addition, such companies operate media outlets and have access to easy/cheap capital,giving it tremendous leverage over pricing of key commodities. It is no crime to go for vertical or horizontal expansion for producing an item,but proper intervention is needed when market share crosses 30% for both the intermediate goods and final goods. I think Bangladesh Competition Commission should intervene more often and regulate such overwhelming market dominating activities. In the west, we see regulators barred major operating software maker to launch new services/product that may curtail competition, discouraged production houses to launch satellite TV network fearing further market concentration, imposed punitive tariff over search engine companies to allow more competition in the industry. We expect similar moves in this country. Awarding license of commodity exchange is a precursor to an information-based market economy that will become more competitive and rescue the consumers and producers from market uncertainties.

Thursday, March 21, 2024

কম্পোজিট

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Composite:যখন objects দের মাঝের সম্পর্ককে part-whole সম্পর্কে রূপ দেয়া যায় এবং user কোন পার্থক্য করতে চায় না সাধারণ object এবং অনেক objects এর composition এর মাঝে তখন Composite Design Pattern ব্যবহার করা হয়। প্রধান অংশগুলো হচ্ছে: Component(composition এ objects এর interface গঠন করে এবং সব class এর জন্য common behavior [এখানে des()] implement করে),Leaf(Composition এর leaf objects কে প্রতিনিধিত্ব করে; leaf/part object এর কোন সন্তান নেই), Composite(যেসব Component objects র সন্তান আছে তাদের behavior কে define করা এবং সন্তানদের ধারণ করা )। উদাহরণে Pen ও Pencil হচ্ছে PencilBox নামের Composite class এর parts/leaves। আবার এরা সবাই Component Item কে implement করছে। তবে Pen ও Pencil সরাসরি implement করছে আর Composite class PencilBox অনুরোধকে forward করছে তার child components এর কাছে।

উদাহরণ:
*/ //component
class Item{
constructor(){}
des(){}
}
//leaf
class Pen extends Item{
constructor(){super();}
des() {
document.write("Pen");
}
}
//leaf
class Pencil extends Item{
constructor(){super();}
des() {
document.write("Pencil");
}
}
//composite
class PencilBox extends Item{
constructor(){
super();
this.a=[];
}
add(s){
this.a.push(s);
}
remove (index){
this.a.splice(index,1);
}
des(){
document.write("Pencil Box:");
for(var k=0;k < this.a.length ; k++)
{
this.a[k].des();
}
}
}
var z=new Pen();
var c=new Pencil();
var b=new PencilBox();
b.add(c);
b.add(z);
b.des();
b.remove(0);
b.des();

চেষ্টা করা যাক:Bookshelf নামে একটি program লিখি। আগের মতই Item হচ্ছে আমাদের Component আর এবার leaf হচ্ছে Book, Exercisebook ও Notebook। Composite হচ্ছে Bookshelf। আগের মতই সবার des() method থাকবে।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Monday, March 18, 2024

La Semaine Dernière A Mes Yeux




(16 mars --- 22 mars)

Cliquez pour voir/cacher
Ma Semaine Gastronomique
Date Petit déjeuner/Début de jeûne Déjeuner Dîner Snacks,Sucreries,Boissons et Fritures/Fin de jeûne
16 Riz,Bronze Featherback poisson,Potato ---- --- Pois chiches,Riz,Tengra poisson,Beguni
17 Riz,Poulet,Pomme de terre --- Riz,Pomme de terre,Vigna Mungo soupe,Tilapia poisson Pois chiches
18 Riz,Tilapia,Vigna Mungo soupe ---- Riz,Vigna Mungo soupe,Œuf dur Pois chiches,Œuf-Pomme de terre tchop
19 Riz,Soupe aux lentilles --- Riz,Indian Potasi poisson Pois chiches,Beguni,Lait
20 Riz,Ompok pabda --- Riz,Omlette Pois chiches
21 Riz,Ompok pabda,Soupe aux vigna mungo --- Riz,Feuilles de pomme de terre,Pomme de terre,Œuf dur Pois chiches,Nouilles
22 Riz,Tilapia,Soupe aux vigna mungo --- --- Riz,Pois chiches,Lait,Pomme de terre tchop,Tilapia poisson

Sunday, March 17, 2024

অবজার্ভার

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Observer:যখন দেখা যায় Objectsদের মধ্যে একটির উপর বাকিরা নির্ভর করে এবং একটির অবস্থার পরিবর্তনের জন্য বাকিদের অবস্থার পরিবর্তনের দরকার পড়ে তখন Observer Design Pattern এর প্রয়োজন পড়ে। এটি Behavioral Design Pattern দলের। প্রধান Components হচ্ছে: Subject এবং Observer। Subject object তার মাঝে এক ঝাক Observer object কে ধারণ করে। Subject object এর যেকোন পরিবর্তন ঘটলে তা Observer object এর method(এখানে update()) এর মাধ্যমে সবাইকে জানিয়ে দেয়া হয়। এটি Publisher-Subscriber নামেও পরিচিত। উদাহরণে class Notifier হচ্ছে আমাদের subject আর MemIntface হচ্ছে Observer Interface আর Member হচ্ছে এর implementation। Notifier এর constructorএ array এর সাহায্যে একগুচ্ছ Observer object সংরক্ষণ করা হচ্ছে। add() আর unsubscribe() হচ্ছে arrayতে item যোগ এবং বাদ দিতে যথাক্রমে push() ও splice() এর মত array methods প্রয়োগ করছে। notifyall() এর মাধ্যমে সকল Observer objectএর update() এর মাধ্যমে পরিবর্তন সম্পর্কে জানানো হচ্ছে। newChange() এ parameter হিসেবে পরিবর্তন টি কি সেটি pass/দেয়া হচ্ছে,তারপর নতুন পরিবর্তনটি কি সেটি constructor এ ঠিক করে সবাইকে notify করা হচ্ছে notifyall() এর মাধ্যমে।

উদাহরণ:
//Observer
class MemIntface{
constructor(){}
update(b){}
}
class Member extends MemIntface{
constructor(c){
super();
this.c=c;
}
getS(){return this.c;}
update(b){
document.write("Dear Mr. "+this.getS()+" a change called '"+b+"' has taken place in our organization.
");
}
}
//Subcject
class Notifier{
constructor(z){
this.z=z;
this.a=[];
this.l=" ";
}
add(m){ this.a.push(m);
}
unsubscribe(integ)
{
this.a.splice(integ,1);
}
notifyall(){
for(var j=0;j < this.a.length ; j++){
this.a[j].update(this.l);
}
}
newChange(b){
this.l=b;
this.notifyall();
}
}
var m=new Member("A");
var z=new Member("B");
var t=new Member("C");
var k=new Notifier("h");
k.add(m);
k.add(z);
k.add (t);
k.unsubscribe(1);
k.newChange("PQR");

চেষ্টা করা যাক:একটি Club তার member দের তার নতুন ফোন নাম্বার পরিবর্তন সম্পর্কে জানাবে। এখানে Subject হচ্ছে Club আর Member আগের মতই Observer। newChange() এর বদলে newPhone() নামের method থাকবে। বাকি সব আগের মতই থাকবে।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Friday, March 15, 2024

আইটেরেটর

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Iterator: এটি Behavioral Design Pattern দলের। Aggregate object যেমন List এর ভেতরকার জিনিস প্রকাশ না করে ক্রম অনুযায়ী item গুলো একে একে প্রবেশের উপায় বের করে এই pattern। List এবং ক্রম অনুযায়ী item গুলো একে একে প্রবেশ করার (traversal) কাজ দুটিকে আলাদা দু'টি interface এ ফেলা হয়। এদের একটি List interface এবং অপরটি হলো Iterator interface। Aggregate object এর নানাবিধ traversal পেতে এই pattern ব্যবহার করা যায় (যেমন সবশেষ item থেকে প্রথম item এ যাওয়া)। এছাড়া একই Iterator interface কে ভিন্ন Aggregate object এর traversal এর কাজেও এই pattern ব্যবহার করা যায়। এখানে কোন Abstract class ব্যবহার করা হয়নি। আমরা চাইলে List ও Iterator এর জন্য দু'টি abstract class নিয়ে দরকারি method ভেতরে জুড়ে দিয়ে তারপর subclassing এর মাধ্যমে interface দু'টির বিকাশ ঘটাতে পারি। যেমন List interface এর Product এবং Beverage নামের দু'টি subclass থাকতে পারে। উদাহরণে ProductList classটির constructor একটি list কে initialize করছে তারপর add() এর সাহায্যে user থেকে item নিয়ে list এর push() কে call করছে । getIterator() নামক factory method এর সাহায্যে ListIterator object তৈরি করছে। ListIterator এর constructorএ list object কে parameter হিসেবে নিচ্ছে আর indexকে initialize করছে। hasNext() দেখছে index কি list এর length এর চেয়ে ছোট কি না; ছোট হলে traversal এর কাজটা চলতে থাকবে। first() প্রথম এবং last() শেষ item কে return করছে। next() একটি থেকে আরেকটি itemএ নিয়ে যাচ্ছে index increment এর সাহায্যে।

উদাহরণ:
class ProductList {
constructor() {
this.list = [];
}
add(item) {
this.list.push(item);
}
getIterator() {
return new ListIterator(this);
}
}
class ListIterator {
constructor(list) {
this.list = list.list;
this.index = 0;
}
hasNext() {
return this.index < this.list.length;
}
first(){return this.list[0];}
last(){return this.list[this.list.length-1];}
next() {
return this.list[this.index++];
}
}
const Product = new ProductList();
Product.add("Milk");
Product.add("Pudding");
Product.add("Butter");
const iterator = Product.getIterator();
while (iterator.hasNext()) {
document. write(iterator.next());
}
document. write(Product.getIterator().first());
document. write(Product.getIterator().last());

চেষ্টা করা যাক: ProducList এর মত BeverageList নিয়ে program টি লিখি। ListIterator এ কেবল জোড় index এর item দেখানোর জন্য একটি method() জুড়ে দিয়ে program টি আবার লিখি।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia,www.geeksforgeeks.org,আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও https://www.geeksforgeeks.org/iterator-method-javascript-design-pattern/ এ ব্যবহৃত program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Thursday, March 14, 2024

Restaurants Face A Bad Spell


Fire killed people in posh neighborhood
Triggering govt's anti-restaurant mood.

Dhaka restaurant business is going through a bad spell. The February 29 fire incident at Bailey Road not only claimed 46 lives but started a long campaign against the restaurants that employ around 100.000 people across Bangladesh. Dhaka restaurants are under the scanner of the government. Graveyard silence fell on Bailey road ,which housed more restaurants and would usually be busy in this time of year if the place were not struck by that fire incident on that February 29 night. What prompted the authority to embark on this drive against the Dhaka restaurants is the number and identity of victims: 3 engineering students (among them one identified as the daughter of a senior police officer),2 journalists, daughter of a garment factory owner who is pursuing her studies abroad, an Italian Bangladeshi and four members of his family who are about to go to Italy, one School teacher and her daughter and many more who could not make it to the news headline.

The restaurant where the tragedy struck is located 2nd floor of a 5-storey building that was meant to be occupied by commercial offices. But restaurants and clothing outlet substituted the offices from the basement to the top floor of the building, which received warning notice from the fire department for not taking enough measures against fire. Even the architect was compelled to object gross violation of building code at his creations to the proper authority.

In Dhanmondi, one of the posh areas of Dhaka, a state-of-the art building is being occupied by high-end restaurants leaving in the dark the very architect who designed it for offices. Like the Bailey road building, gas cylinders of the restaurants are being kept on every floor of the building that does not even have a proper fire exit in case of emergency situation.

Authorities’ concerns about safety and building code violation following the tragedy are genuine. But the way they responded to such tragedy calls into question their objective and commitment to enforce building code. It is not the task of the authority to spread further panic and to harm an industry that is creating decent jobs and filling government coffer with VAT money. Authority is supposed to aware the consumers about potential dangers of visiting such restaurants instead of starting a panic spree.

The subsequent driving incident could be aptly called incoherent policies of the respective authorities. Right before their eyes these restaurants popped up on every floor of commercial buildings across Dhaka. They remained mum back then. When one fatal incident surfaced and created storm into tea cups ,they become hyperactive and literally put an end to the restaurant business in the time of austerity.

Origin of the fire and scale of devastation require proper scrutiny. Vital question like is it an accident or a deliberate attack? needs to be answered. Before the probe coming up with convincing findings, drawing a definitive conclusion may complicate further the problem. Last year, on the eve of Eid, we witnessed how several of Dhaka's markets were ravaged by mysterious fire. In Bangladesh, we see frequent fire incidents like the retributive fire attacks in Mexico, Philippines and other countries where organized criminal groups hold sway over society and economy. It is highly indicative of a country that sees introduction of undocumented money into the economy and gradual decline of power of law enforcement agencies. Like many other previous incidents In the case of Bailey road, we read how the fire spread at unprecedented pace and plumes of smokes consumed the victims, giving them no time to think about alternatives. Restaurant business is not flawless. I often wonder how these restaurants thrive when the middle class is loosing its purchasing power and sees opportunities shrink everyday. What is puzzling is that Banani-11 street model has been being replicated across Dhaka for the last couple of years. NBR could tell how much VAT they gave to the govt. Apart from that ,the high-end restaurants created some good jobs. Their frequent occupation of commercial floors lays bare the fact that real estate sector has so many unrented commercial spaces. This means businesses are having a tough time. Similarly, speculation like money laundering behind the smokescreen of restaurant business cannot be ruled out. Especially when govt allows investment of undocumented money in the real-estate sector and more and more restaurants occupy office spaces of a building. Putting aside the issue of occupancy certificate, Govt probe should focus on whether they are engaged in money laundering activity or not. Money laundering accusation is labelled against many people often on purely harassing purposes but its genuine sources are never being investigated by the authority. This is another example of biased use of law.

However, it is also not right to harass the restaurant owners during the fasting month of Ramzan when the business in general sees a low revenue. More documentation, origin of the capital invested and a sustained campaign among restaurateurs and consumers may discourage owners from renting an office space. Arbitrary fining of the restaurants and shutting them down are only hurting the govt that is keen to create more jobs in the next few years. Let deep thought and sanity prevail over reactionary stance.

Wednesday, March 13, 2024

সিঙ্গলটন

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Singleton:এটি Creational Design Pattern দলের। এক্ষেত্রে একটি ক্লাসের কেবল একটি instance তৈরি করা হয়। উদাহরণে Person এর constructor এ শর্ত জুড়ে দেয়া আছে যে একের বেশি instance তৈরি করলে বার্তা দেখাবে যে এই class এর কেবল একটি instance সম্ভব। তারপরও কেউ যদি instance/object তৈরি করতে চায় তবে comment out(/*…*/ উঠিয়ে দেই) করে এবং throw কে comment এর মধ্যে ফেলে অগ্রসর হতে পারে। তবে সেক্ষেেত্রেও নতুন instance একই object কে নির্দেশ করবে। উদাহরণে p ও q একই object কে বোঝাচ্ছে।Strict equality operator(===) এক্ষেত্রে true নির্দেশ করছে যা বলছে দু'জনে একই objectকে refer করছে।আর যদি আমরা comment out না করে current set up থাকি তবে দ্বিতীয় instance (q) তৈরির সময় আমাদেরকে অপারগতার বার্তা দেখাবে। এখানে দু'টি private field রয়েছে(s ও obj) , এর মাঝে obj আবার static যাকে Class Person এর মাধ্যমে access করতে হবে।

উদাহরণ:
class Person{
#s="Hi
";
static #obj=null;
constructor(){
if (Person.#obj){
throw document.write("Only one instance can be created!
");
/*
return Person.#obj;
*/
}
Person.#obj=this;
}
getS(){ return this.#s;}
show (){
document.write(this.getS());
}
}
var p=new Person();
p.show();
var q=new Person();
q.show();
/*
document. write(p===q);
if(p===q){
document. write("
Since p and q have pointed to the same object,singleton class Person works!");
}
else{
document. write("
p and q are not same as they pointed to different objects!");
}
*/

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia,www.stackoverflow.com,আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও https://stackoverflow.com/questions/1479319/simplest-cleanest-way-to-implement-a-singleton-in-javascriptএ ব্যবহৃত program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Monday, March 11, 2024

মেডিয়েটর

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Mediator: এটি Behavioral Design Pattern দলের।এখানে objects নিজেদের মধ্যে communicate না করে mediator এর মাধ্যমে communicate করে।এখানে objects দের মধ্যে সরাসরি নির্ভরশীলতা কমিয়ে loose coupling কে উৎসাহিত করা হয়েছে আর objectsদের মধ্যে Communication এর ভার দেয়া হয়েছে Mediator class কে। প্রধান তিনটি components হচ্ছেঃ Mediator,Concrete Mediator( Mediator এর implementation) এবং Colleague (যার objects এর মধ্যে সরাসরি যোগাযোগ হবে না)। উদাহরণে Colleague class O এর methods হচ্ছে message() ও received ()।একই নামে Mediatorএও দু'টি method আছে তবে তারা parameter হিসেবে O এর object নেয়। A এর object তৈরি করে যখন message () কে ডাকা হয়েছে তখন প্রথমে Mediator এর message () কে ডাকা হয়েছে তারপর ভেতরের বার্তা দেখানো হচ্ছে। C এর object যখন received() কে call করছে তখন একই রকম ব্যাপার ঘটছে।

উদাহরণ:
class O{
constructor(m){this.m=m;}
id(){}
message(){}
received (){}
}
class A extends O{
constructor(s,m){super(m);
this.s=s;}
id(){return this.s;}
message(){
this.m.message(this);
document.write(this.id()+": Hello there! How are you?");
}
received(){
this.m.received(this);
document.write(this.id()+": Fine! Thank you!");
}
}
class C extends O{ constructor(s,m){super(m); this.s=s;}
id(){return this.s;}
message(){
this.m.message(this);
document.write(this.id()+": Hello there! How are you?");
}
received(){
this.m.received(this);
document.write(this.id()+": Fine! Thank you!");
}
}
class M{
constructor (){}
message(O){}
received(O){}
}
class ConcreteM extends M{
constructor(){super ();}
message(O){
document.write(" Mediator forwards a message from "+O.id()+" to others."); }
received(O){
document.write(" Mediator receives a message sent by "+O.id()+" for others.");
}
}
var m=new ConcreteM();
var a=new A("obj1",m);
var s=new A("obj2",m);
a.message();
s.received();

চেষ্টা করা যাক: একটি অফিসের বিভিন্ন বিভাগের মধ্যে বার্তা আদান-প্রদান হচ্ছে । PABX হচ্ছে এখানে Mediator আর Department হচ্ছে Colleague interfaceআর A ও C হচ্ছে তার implementation। সবার sent() ও received () নামের method থাকবে।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia,www.geeksforgeeks.org,আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Sunday, March 10, 2024

La Semaine Dernière A Mes Yeux




(09 mars --- 15 mars)

Cliquez pour voir/cacher
Ma Semaine Gastronomique
Date Petit déjeuner/Début de jeûne Déjeuner Dîner Snacks,Sucreries,Boissons et Fritures/Fin de jeûne
09 Pain,Pomme de terre Riz,Ompok pabda,Soupe aux haricots mungo avec tête de Ruhi Riz,Purée de pomme de terre,Soupe aux haricots mungo avec tête de Ruhi ----
10 Khichuri Riz,Soupe aux lentilles,Purée de pomme de terre,Feuilles de Pomme de terre Riz,Soupe aux lentilles,Pomme de terre ---
11 Pain,Omelette Riz,Soupe aux lentilles,Pomme de terre,Œuf dur,Feuilles d'amarante tige Riz,Œuf dur,Feuilles d'amarante tige ---
12 Riz,Œuf dur,Poulet --- Riz,Pomme de terre ,Œuf dur,Mudskipper, Lait,Pain Pois chiches,Lait
13 Riz,Pomme de terre,Poulet,Mudskipper poisson --- Pain,Lait Pois chiches,Khichuri
14 Riz,Œuf dur,Pomme de terre --- Riz,Pain,Œuf dur,Ruhi,Pomme de terre Pois chiches
15 Riz,Pomme de terre,Ruhi --- Riz,Pomme de terre,Poisson phali Pois chiches,Beguni,Pain,Lait

Saturday, March 9, 2024

ইন্টারপ্রেটার

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Interpreter:অক্ষর আর ধ্বনি নিয়ে হয় শব্দ আর অনেক শব্দ নিয়ে হয় বাক্য। আবার বাক্যে শব্দের ব্যবহার ,বাক্য গঠন , সময়/কাল অনুযায়ী বাক্যের ধরণ এসব বিষয় ঠিক করতে তৈরি করা হয়েছে ব্যাকরণ। কাজেই ভাষার ব্যাকরণটি বুঝতে পারলে আমরা বাক্যের অর্থ আর কোন কাল/সময়কে নির্দেশ করছে সেটি বুঝতে পারি। ঠিক তেমনিভাবে program লিখতে গিয়ে আমরা যদি তার ভেতরের ব্যাকরণগুলিকে সুনির্দিষ্ট করতে পারি এবং তা ব্যাখ্যা করবার জন্য কোন interpreter এর সাহায্য নেই তবে সেটি হয়ে দাঁড়ায় আমাদের Interpreter Design Pattern। উদাহরণে চিহ্ন দিয়ে ডানে/বামে যাবার দিক নির্দেশনা দেয়া হচ্ছে। যে চিহ্ন ব্যবহার করা হচ্ছে তার প্রত্যেকটিকে এক একটি নিয়ম/ব্যাকরণ হিসেবে ধরা যায়। এজন্য “->” এই নিয়মটি/ব্যাকরণকে ব্যাখ্যা করা হচ্ছে “ Go right” এবং “<-” এটিকে ব্যাখ্যা/interpret করা হচ্ছে “ Go left” হিসেবে। ABS class এই নিয়মগুলির একটি abstract class যার method হচ্ছে interpret() আর Right ও Left হচ্ছে তার implementation। Context class টিতে interpret() এ কোন ব্যাখ্যা বা interpretation যাবে তা দেয়া আছে যথাক্রমে right() ও left() নামক method দু'টিতে। Context class এর object এ একটি string variable দেয়া আছে যাকে বলা হবে ডান/বামে যাবার কথা। Client class এর object এ Context এর object আর string variable pass করা হচ্ছে ডান/বামের চিহ্ন বোঝানোর জন্য।ABS class টিতেও Context এর object pass করা হয়েছে। Client এ প্রথমে ABS class এর object গঠন করা হয়েছে ,পরে চিহ্ন/string variable অনুযায়ী প্রযোজ্য subclass এর object assign করা হয়েছে এবং তার interpret () কে invoke করা হয়েছে। এখানে Open-Closed Principle এর প্রয়োগ হচ্ছে। আমরা চাইলে "U" নামে (যার interpretation হচ্ছে "Make a U-turn") subclass যোগ করে ABS interface এর বিকাশ ঘটাতে পারি। Interpreter Design Pattern কে Behavioral Design Pattern এর দলে ফেলা হয়।

উদাহরণ:
class Context{
constructor(c){this.c=c;}
plain(c){return new Context(" ");}
special (c){return new Context(c);}
right(){
return this.c+" Go right";
}
left(){
return this.c+" Go left";
}
}
class ABS{
constructor(t){this.t=t;}
interpret(){
}
}
class Right extends ABS{
constructor(t){super(t);}
interpret(){
return this.t.right();
}
}
class Left extends ABS{
constructor(t){super(t);}
interpret(){
return this.t.left();
}
}
class Client{
constructor (c){
this.c=c;}
transInter(s){
var a=new ABS(this.c);
if(s=="->")
{
a=new Right(this.c);
return a.interpret ();
}
else if(s=="<-")
{
a=new Left(this.c);
return a.interpret ();
}
else{
return "Sorry, not defined.\n";
}
}
}
var c=new Context("w");
var a=new Client(c);
document.write(a.transInter("->"));

চেষ্টা করা যাক: একটি program লিখি যা একটি সংখ্যাকে decimal ও percentage এ প্রকাশ করবে। Context class এবার argument হিসেবে নিবে একটি integer আর method হিসেবে থাকবে decimal() আর percent() যেখানে decimal আর percent বের করবার নিয়ম দেয়া আছে । আর ABS class এর implementation হিসেবে Decimal ও Percentage নামের দুটি subclass থাকবে। যাদের interpret() মেথড থাকবে যেখান থেকে Context এর object এর মাধ্যমে প্রযোজ্য ব্যখ্যা কে call করা হবে। ABS class এ কিন্তু Context এর object দেয়া আছে। Client class ও Context এর object নিচ্ছে আর তার interpret() method একটি string variable নিচ্ছে argument হিসেবে যেটি “dec” বা “percent” নামক string এর সাথে মিলে গেলে প্রযোজ্য object গঠন করে interpret() method invoke করবে। নচেৎ “Sorry,not defined!” বার্তা দেখাবে।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Thursday, March 7, 2024

Fighting Inflation Continues


Fuel Price adjustment and tight policy rate
May cause inflation to attain the target.

Govt has cut prices of oil: price of diesel is cut by Taka 0.75/liter, price of octane is cut by Taka 4 /liter and price of petrol is cut by Taka 3/liter. The move is in line with govt's pledge to the IMF. From now onwards govt will adjust the fuel prices every month. In 2022,govt raised the fuel prices by Taka 50/liter in one fell swoop. All these years fuel prices remained high in spite of the fact that on some occasions fuel prices fell at international market. Despite huge criticism, govt did not lend ear to those shouts. Even the IMF First Review Report identified fuel prices as one of the factors influencing the inflation:

“Headline inflation reached a decade high of 9.9 percent year-on-year in August 2023,reflecting both recurrent cost-push shocks from both high and volatile food and fuel prices as well as the pass-through from Taka depreciation. “

Kitchen market volatility also stems from high fuel prices among other things. Government decided to not lower the diesel prices much fearing leakages/black market activity.High fuel price raises cost of black market activity and stops oil smuggling. This ,however, does not bar govt rationalizing the prices, bringing ease to everyone's life. For some reasons govt abstained from lowering fuel prices all these years, swelling Bangladesh Petroleum Corporation’s (BPC) profit.

Policy rate hike contained non-food inflation. But food inflation pushed the inflation high. Luckily February data shows that inflation has lowered to 9.67% from 9.86% in January. Monetary tightening measures are working but slowly and face criticism. Often causes of inflation are put forward as argument and ongoing policies are called into question. IMF First Review Report stresses on monetary tightening among others to bring back macroeconomic stability in coming months:

“…current pace of monetary tightening seems appropriate and the authorities based on the incoming macroeconomic should continue the current tightening bias until the disinflation process is firmly established. “(P-10,IMF First Review Report)

In addition to the monetary tightening, the review report also underscores neutral fiscal policy stance and flexible exchange rate to get the economy on track. We witnessed that government cut spending on export subsidies and introduced band corridor for the exchange rate of Taka against USD. Policy rate hike along with fuel price adjustment, a liberal exchange rate and low budget deficit target are likely to bring good news in coming months.

Monday, March 4, 2024

আ্যব্সট্রাক্ট ফ্যাক্টরি

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Abstract Factory: এটি তৈরি করে এমন এক interface যা একই ধরণের object গঠন করতে সাহায্য করে। এটি ব্যবহার করতে হয় যখন একটি system আলাদা থাকবে object গঠন ও প্রতিনিধিত্ব থেকে। একই ধরণের product এর objects কে একসাথে ব্যবহারের জন্য design করতে হলেও এর ব্যবহার করতে হয়।এটি client/user কে আলাদা করে class implementation থেকে। client /user কেবল abstract interface এর মাধ্যমে object কে manipulate করতে পারে। উদাহরণে Product এবং Shop interface দু'টির implementation হচ্ছে যথাক্রমে Pastry ও Flour এবং PastryShop ও Grocery। PastryShop এর des() মেথডে Pastry এর object গঠন করে তার des() methodকে ডাকা হচ্ছে। একই ঘটনা ঘটছে Grocery তে Flour objectকে ঘিরে। Shopmaker class এর সাহায্যে client কেবল shop() মেথডের মাধ্যমে যে ধরণের shop চায় তা string argument এর মাধ্যমে জানিয়ে দিবে। এখানে আগে থেকে shop abstract class এর object তৈরি করা আছে। string argument অনুযায়ী সংশ্লিষ্ট class object তৈরি করে তা assign করা হবে abstract object কে। Default হিসেবে PastryShop এর object গঠন করা হয়েছে। কাজেই এখানে client/user কে Product ও Shop এর Implementations থেকে আলাদা করা হয়েছে।এটি Creational Design Pattern দলের।

উদাহরণ:
class Product{
constructor (){}
des(){}
}
class Pastry extends Product{
constructor(){super();}
des(){
return " Pastry and cakes.";
}
}
class Flour extends Product{
constructor (){super();}
des(){
return " Flour";
}
}
class Shop{
constructor(){}
des(){}
}
class PastryShop extends Shop {
constructor(){super();}
des(){
var p=new Pastry();
document.write("Pastry shop sells "+p.des()+"
"); }
}
class Grocery extends Shop {
constructor(){super();}
des(){
var f=new Flour();
document.writeln("Grocery sells "+f.des()+"
");
}
}
class ShopMaker{
constructor (){}
shop(s){
var a=new Shop();
if( s=="pastry") {
a=new PastryShop();
return a;
}
else if(s=="grocery"){
a=new Grocery();
return a;
}
else{
a=new Pastry ();
return a;
}
}
}
var s=new ShopMaker();
var k=s.shop("grocery");
k.des();

চেষ্টা করা যাকঃ Rack ও Item নামের দু'টি interface বানাই যাদের যথাক্রমে BookShelf ও ShoeRack এবং Book ও Shoe নামের subclass থাকবে। এদের des() মেথড থাকবে। BookShelf এর des() দেখাবে "On bookshelf, we keep books." বার্তা আর ShoeRack এর des() দেখাবে "On shoerack, we keep shoes." বার্তা। RackMaker নামে আরেকটি class থাকবে যেটির rack() মেথড client/user এর পছন্দ অনুযায়ী Rack object তৈরি করবে।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

La Semaine Dernière A Mes Yeux




(02 mars --- 08 mars)

Cliquez pour voir/cacher
Ma Semaine Gastronomique
Date Petit déjeuner Déjeuner Dîner Snacks,Sucreries,Boissons et Fritures
02 Pain,Omelet Riz,Ruhi,Épinard d'éléphant Riz,Ruhi,Épinard d'éléphant Lait
03 Paratha,Omelette Riz,Soupe aux lentilles,Ruhi Riz,Haricots avec sec poisson bombili,Pianju ---
04 Patate douce Riz,Pomme de terre,Soupe aux lentilles Riz,Pomme de terre bhaji,Soupe aux lentilles,Pianju ---
05 Pain,Omelette Riz,Soupe aux lentilles,Épinard d'éléphant Riz,Soupe aux lentilles Biscuit
06 Pain,Omelette,Lait Riz,Soupe aux lentilles Riz,Soupe aux lentilles,Pomme de terre bhaji Patate douce,Biscuit
07 Pain,Pomme de terre bhaji Riz,Poisson avec pomme de terre Riz Poisson avec pomme de terre Lait
08 Pain,Omelette Riz,Ompok pabda poisson Riz,Ompok pabda poisson,Soupe aux lentilles Patate douce

Sunday, March 3, 2024

ডেকোরেটর

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Decorator: এটি object এ বাড়তি বৈশিষ্ট্য/দায়িত্ব যোগ করে থাকে।নাম শুনেই বোঝা যায় এটি objectকে decorate করছে।program এ বৈশিষ্ট্য বাড়াতে এটি subclassing এর বিকল্প হিসেবে কাজ করে।এই বৈশিষ্ট্য/দায়িত্ব যোগ করবার ঘটনাটি ঘটে মূলতঃ runtime এ । Decorator class টি মূল class/Component class টিকে মুড়ে ফেলে বলে একে wrapper ও বলা হয়।
উদাহরণে Greet এর subclass হল CoGreet,Decorator ও AddDecorator। Decorator ও AddDecorator subclass এর constructor এ CoGreet কে reference হিসেবে নেয়া হয়েছে। Decorator এর des() method এ Cogreet এর des() method এর সাথে বাড়তি বৈশিষ্ট্য(যেটি user দিবে) যোগ করা হচ্ছে। AddDecorator এ আবার বৈশিষ্ট্য যোগ হচ্ছে এর উপর।কাজেই এখানে CoGreet এর des() method কে Decorator ও AddDecorator এর বাড়তি বৈশিষ্ট্য দিয়ে মুড়ে দেয়া হচ্ছে।runtime এ Decorator object এ ‘~~~’ এবং AddDecorator object এ ‘####’ দু'টি নকশা CoGreet object এ যোগ করা হয়েছে। User এর খুশিমত নকশা এখানে runtime এ যোগ করা যাচ্ছে ,আলাদা করে subclass করতে হচ্ছে না।Structural Design Pattern এর দলে Decorator পরে।

উদাহরণ:
class Greet{
constructor(){}
des(){}
}
class CoGreet extends Greet{
s="Hello! Decorator example!";
d=03;
m=03;
y=2024;
constructor(){
super();
}
des(){
document.write(this.s+this.d+"/"+this.m+"/"+this.y);
}
}
class Decorator extends Greet{
constructor(a,r){
super();
this.a=a;
this.r=r;
}
des() {
return this.r.des()+this.a;
}
}
class AddDecorator extends Greet{
constructor(a,r){
super();
this.a=a;
this.r=r;
}
des() {
return this.r.des()+this.a;
}
}
var g= new CoGreet();
var s=new Decorator("~~~~~~~~~~~~~~~~~",g);
var w=new AddDecorator("####################", s);
document.write(w.des());

চেষ্টা করা যাক: একটি program লিখি যেখানে নাম ও নামের নিচে ‘πππππ’ নকশা দেখা যাবে। Name নামের interface থাকবে যার subclass হিসেবে থাকবে FullName ও Decorator। এদের des() নামের method থাকবে। দ্বিতীয়বার program run করবার সময় 'πππππ'বাদ দিয়ে পছন্দমত নকশা যোগ করি।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com

Saturday, March 2, 2024

কমান্ড

কাদের জন্যঃ Object-oriented programming language সম্পর্কে ধারণা আছে এমন মানুষ।

যা প্রয়োজনঃclass,inheritance,composition,JavaScript সম্পর্কে পূর্ব ধারণা।

Command: এই pattern এ কোন class কোন কাজ সরাসরি নিজে না করে কোন command object এর মাধ্যমে করে এবং এটি কাজটি করতে পারে এমন objectকে আলাদা করে(decouple) কাজটি করবার জন্য বলছে এমন object থেকে ।আর class এর method গুলো আলাদা Command object এর মাধ্যমে সম্পন্ন করা হয়। চারটি অংশ রয়েছে এই pattern এ:

  • Command: যেটি Receiver object এর method কে call করছে।Command subclass এ Receiver object জমা থাকে। Receiver object আর কাজটির মধ্যে binding তৈরি করে দেয়।
  • Receiver: যার method command object করে দিচ্ছে।
  • Invoker:এটি জানে কিভাবে request করতে হয় command execute করবার জন্য। Command interface সম্পর্কে জানে তবে subclass/concrete Command সম্পর্কে জানে না।
  • Client: যে Receiver,Command এবং Invoker class সম্পর্কে জানে এবং ঠিক করে দেয় কোন Receiver object কে কোন Command object এ দিতে হবে আর কোন Commandটি Invoker দিয়ে করাতে হবে।

উদাহরণে TV Receiver class এর On() আর Off() নামের method দুটি TVOn আর TVOff নামের দুটি Command subclass এর perform () method এর মাধ্যমে সম্পন্ন করা হচ্ছে। Command subclass দু'টিতে Receiver class TV object আছে।TVOn subclassএ TV object আর On() method এর মধ্যে একটি binding তৈরি হয়েছে যা perform() এর মাধ্যমে বোঝা যাচ্ছে। আবার TVOff subclassএ একই ঘটনা ঘটছে Off() method কে ঘিরে। Invoker এর set() methodএ Command interface কে argument হিসেবে pass করা হয়েছে । আর action() method প্রযোজ্য Command object এর perform () method কে সংশ্লিষ্ট কাজ করার অনুরোধ করছে।

উদাহরণ:
class Command{
constructor(){}
perform(){}
}
//Receiver
class TV{
constructor(){}
on(){
document. write("Tv is on.
");
}
off(){
document. write("Tv is off.
");
}
}
class TVOn extends Command{
constructor( a){super();
this.a=a;}
perform(){
this.a.on();
}
}
class TVOff extends Command{
constructor(a){super();
this.a=a;}
perform(){
this.a.off();
}
}
class Invoker{
constructor(){}
set(a){this.a=a;}
action(){
this.a.perform();
}
}
//Client/User decides here
var k=new Invoker();
var t=new TV();
var s=new TVOn(t);
k.set(s);
k.action();

চেষ্টা করা যাক: BedSwitch নামে একটি program লিখতে হবে। BedSwitch নামের Receiver এ on() এবং off() নামে দু'টি method থাকবে। Command নামের abstract class এর SwtichOn এবং SwitchOff নামের subclass থাকবে।এদের সবার perform() নামক method থাকবে। আগের মতই Invoker থাকবে যার set() ও action() নামের method থাকবে।

কৃতজ্ঞতাঃ এই লেখা তৈরি করতে দরকারি তথ্য নেয়া হয়েছে Wikipedia, আকর বই "'Design Patterns:Elements Of Reusable Object-Oriented Software' by Eric Gamma,Richard Helm,Ralph Johnson and John Vlissides(Addisson-Wesley.1994)" ও আমার তৈরি করা নানা program থেকে।
মন্তব্য ও যোগাযোগঃ mrh4478@gmail.com