Wednesday, June 24, 2015

Interesting Conscious Dream on 24th June, 2015

I was quiet surprised by the dream I saw early in the morning between 8:00 to 10:30 am. It might be the effect of numerous fictional  movies like Gravity, inception etc ,tv series like "The flash" where people can time travel in the past although it does not seems to be realistic in real life. But everything is possible in dream. It was interesting dream for me so I thought I should note it down somewhere.

On 24th June, 2015 I woke up early in the morning at around 6:00 am and felt kind of hazzy and slept till 7:30 again I had thought I should wake up and study and tried to study using my laptop , even than my mind was heavy and didn't felt like I had a good sleep so I slept again from 8:20 and this is where my real dream begins... I travelled back to 2010 in Nepal in my dream. As usual, during my bachelor's degree , I was with my friends, approaching towards the  cafe because of the lecture break hour. In my dream, I was in the cafe with three of my friends ordering the tea and trying to find some snacks. Untill now, it was so real that I could not felt it was a dream, we were discussing about the class and suddenly, I felt that how can I be in bachelor's degree , I had already graduated my bachelors  and started my master's degree. For me during that time in my dream, I felt like I know the future of them at least where they will be in 2015 and what will they be doing. I told them in my dream, that I don't belong to this time, believe me !!!, I have already been studying my master's in Germany and now how could I be here. They started laughing at me and thought I have got crazy. I tried to persuade them that now I am in a deep sleep and travelled back to the past in 2010. Everything felt so real.. real people , real food, real discussion, real laughing, real feeling, real feeling of not believing you...Until now they could not believe me. Fortunately , I had my university bag with the class notes along with dates, I showed them all the notes and lectures that I had in my Master's lecture in Germany. They saw all the dates of 2014, 2015, even though we were in 2010 in my dream which made them crazy for a while....

I said them I don't belong to this time but in the future, it was actually a sentence said by Dr. will in the tv series "The Flash". And the concept of having deep sleep and traveling back might have came from the movie "Inception". I told them that, we will have a big devastating earthquake in Nepal on 18th  November, 2015 (which was not the actual date in reality, it was on 25th April but yeahh it was a dream) so please do whatever you can to protect your family and friends and society. I suggested them during that period, suggest your family to leave kathmandu and travel to terai for 2 or 3 weeks because kathmandu will have  huge destruction along with other districts. So please believe me prepare well for the upcomming  destuctive earthquake in 2015. I told one of my friend who was from bhaktapur that you will be organising the rescuse , relief programme in bhaktapur after the earthquake, most of the monuments will be gone etc... I told all of them that if their mom or relatives wanted to travel to terai , just let them go before the actual earthquake.... (All these converstion happened in my dream)


Again I was kind of afraid that how can I be in such a long deep sleep, I might be in that time forever because everything was too realistic. And than I thought if this is a dream ,   I should try to wake up now and tried to  move physically and I was back to my consiousness....Slowly I opened my eyes and I was in my bed in Munich, with a glowing sunlight outside my window at 10:30 am. I was feeling fresh this time with clear and light mind.....And than grabbed a coffee and here I am writing this blog......

How strange dreams are ? our cortex tries to interpret all the signals generated in the brain in whatever possible ways it can.


Thanks for reading this blog.... :)

Friday, June 19, 2015

Create sample web app with prebuild user-login module using Nodejs, Express js and bootstrap

Source:  https://stormpath.com/blog/build-nodejs-express-stormpath-app/
Note: Do not forget to run npm install module-name, if there is an error prompting module is not found
Here at Stormpath we <heart> Node.js – it’s so much fun to build with! We’ve built several libraries to help node developers achieve user management nirvana in your applications.
If you’ve built a web app before, you know that all the “user stuff” is a royal pain. Stormpath gives developers all that “user stuff” out-of-the-box so you can get on with what you really care about – your app! By the time you’re done with this tutorial ( < 15 minutes, I promise), you’ll have a fully-working Express app.
We will focus on our Express-Stormpath library to roll out a simple Express.js web application, with a complete user registration and login system, with these features:
  • Login and Registration pages
  • Password reset workflows
  • A profile page for your logged in users
  • A customizable home page
  • The ability to add other Stormpath features in our Express-Stormpath library (API authentication, SSO, social login, and more)
In this demo we will be using Express 4.0, we’ll discuss some of the great features of Express 4.0 as we go along. I will be using my Mac, the Terminal app, and Sublime Text for a text editor.

What is Stormpath?

Stormpath is an API service that allows developers to create, edit, and securely store user accounts and user account data, and connect them with one or multiple applications. Our API enables you to:
  • Authenticate and authorize your users
  • Store data about your users
  • Perform password and social based login
  • Send password reset messages
  • Issue API keys for API-based web apps
  • And much more! Check out our Product Documentation
In short: we make user account management a lot easier, more secure, and more scalable than what you’re probably used to.
Ready to get started? Register for a free developer account athttps://api.stormpath.com/register

Start your project

Got your Stormpath developer account? Great! Let’s get started.. vroom vroom
If you don’t already have Node.js on your system you should head over tohttps://nodejs.org and install it on your computer. In our examples we will be using a Mac, all commands you see should be entered in your Terminal (without the $ in front – that’s a symbol to let you know that these are terminal commands)
Step one is to create a folder for this project and change into that directory:
$ mkdir my-webapp
$ cd my-webapp
Now that we are in the folder we will want to create a package.json file for this project. This file is used by Node.js to keep track of what libraries (aka modules) your project depends on. To create the file:
$ npm init
You will be asked a series of questions, for most of them you can just press enter to allow the default value to be used. Here is what I chose, I decided to call my main file app.js, I set my own description and set the license to MIT – everything else I just pressed enter on:
Press ^C at any time to quit.
name: (my-webapp)
version: (0.0.0)
description: Website for my new app
entry point: (index.js) app.js
test command:
git repository:
keywords:
author:
license: (ISC) MIT
About to write to /private/tmp/my-webapp/package.json:

{
  "name": "my-webapp",
  "version": "0.0.0",
  "description": "Website for my new app",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "MIT"
}


Is this ok? (yes) yes
With that I will now have a package.json file in my folder. I can take a look at what’s in it:
$ cat package.json

{
  "name": "my-webapp",
  "version": "0.0.0",
  "description": "Website for my new app",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "MIT"
}
Looks good! Now let’s install the libraries we want to use. You can install them all with this command:
$ npm i --save express express-stormpath jade forms csurf xtend
The save option will add this module to your dependencies in package.json. Here is what each module does:
  • Express.js is the web framework that everything else is built on
  • Express-stormpath provides convenience features that can be tied in to the Express app, making it very easy to use Stormpath’s features in Express
  • Jade is a templating engine for writing HTML pages
  • Forms is a module that will take the pain out of validating HTML forms
  • Csurf adds CSRF protection to our forms
  • Xtend is a utility library that makes it easy to copy properties from one JavaScript object to another.

Gather your API Credentials and Application Href

The connection between your app and Stormpath is secured with “API Key Pair”. You will provide these keys to your web app and it will use them when it communicates with Stormpath. You can download your API key pair in our Admin Console. After you login you can download your API key pair from the home page, it will download theapiKey.properties file – we will use this in a moment.
While you are in the Admin Console you want to get the href for your default Stormpath Application. In Stormpath, an Application object is used to link your web app to your user stores inside Stormpath. All new developer accounts have an app called “My Application”. Click on “Applications” in the Admin Console, then click on “My Application”. On that page you will see the Href for the Application. Copy this — we will need it shortly.

Writing the application entry (app.js)

It’s time to create app.js, this will be the entry point for your server application. You can do that from Sublime Text or you can do this in the terminal:
$ touch app.js
Now open that file in Sublime Text and put the following block of code in it:
var express = require('express');
var stormpath = require('express-stormpath');

var app = express();

app.set('views', './views');
app.set('view engine', 'jade');

var stormpathMiddleware = stormpath.init(app, {
  apiKeyFile: '/Users/robert/.stormpath/apiKey.properties',
  application: 'https://api.stormpath.com/v1/applications/xxx',
  secretKey: 'some_long_random_string',
  expandCustomData: true,
  enableForgotPassword: true
});

app.use(stormpathMiddleware);

app.get('/', function(req, res) {
  res.render('home', {
    title: 'Welcome'
  });
});

app.listen(3000);
You’ll need to set the location of apiKeyFile to be the location on your computer where you saved the file. You also need to set the application href to be the one that you looked up earlier.
The secretKey value should be changed as well, this will be used as a key for encrypting any cookies that are set by this webapp. I suggest using a long, random string of any type of character.
In this example we’ve enabled some stormpath-specific options, they are:
  • The password reset flow via enableForgotPassword – this will enable a password reset page at /forgot
  • Auto-expansion of custom data – this will come in handy later when we build the profile page
There are many more options that can be passed, and we won’t cover all of them in this demo. Please seee the Express-Stormpath Documentation for a full list

Create your home page

Let’s get the easy stuff out of the way: your home page. Create a views directory and then create a Jade file for the home page:
$ mkdir views
$ touch views/home.jade
Now open that file in Sublime Text and put the following in it:
html
  head
    title=title
    link(href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css', rel='stylesheet')
  body
    div.container
      div.jumbotron
        h1 Hello!

        if user
          p Welcome, #{user.fullName}
          p
            a.small(href="profile") Edit my profile
          a.btn.btn-primary(href="/logout") Logout
        else
          p Welcome to my app, ready to get started?
          p
            a.btn.btn-primary(href="/login") Login now
          p
            span.small Don't have an account?
            span &nbsp;
            a.small(href="/register") Register now
This is a simple view that will prompt a new visitor to log in, or greet a registered user if they have already logged in.
With that… we’ve got something we can look at!

Run the server – It’s Aliiiive!

I kid you not: your application is ready to be used. Just run this command to start the server:
$ node app.js
This will start your app which is now running as a web server on your computer. You can now open this link in your browser:
You should see your home page now:
Node App Home
Go ahead, try it out! Create an account, you will be redirected back to the home page and shown your name. Then logout and login again, same thing! Pretty amazing, right??

Pro tip: use a file watcher

As we move forward we will be editing your server files. You will need to restart the server each time. You can kill the server by typing Ctrl + C in your Terminal. But I suggest using a “watcher” that will do this for you.
I really like the Nodemon tool. You can install it globally (it will always be ready for you!) with this command:
$ npm install -g nodemon
After installation, you can then run this command:
$ nodemon app.js
This will start your server and watch for any file changes. Nodemon will automatically restart your server if you change any files – sweet!

Create the profile page

A common feature of most sites is a “Dashboard” or “profile” page – a place where your visitor provide some essential information.
For example purposes, we’re going to build a profile page that allows you to collect a shipping address from your visitors. We will leverage Custom Data, one of the most powerful features of stormpath
To begin, let’s create a new view for this dashboard:
$ touch views/profile.jade
And a JavaScript file where the route handler will live:
$ touch profile.js
Now we’ve got some copy-and-paste work to do. These two files are pretty big, so we’ll explain them after the paste.
Paste this into profile.js:
var express = require('express');
var forms = require('forms');
var csurf = require('csurf');
var collectFormErrors = require('express-stormpath/lib/helpers').collectFormErrors;
var stormpath = require('express-stormpath');
var extend = require('xtend');

// Declare the schema of our form:

var profileForm = forms.create({
  givenName: forms.fields.string({
    required: true
  }),
  surname: forms.fields.string({ required: true }),
  streetAddress: forms.fields.string(),
  city: forms.fields.string(),
  state: forms.fields.string(),
  zip: forms.fields.string()
});

// A render function that will render our form and
// provide the values of the fields, as well
// as any situation-specific locals

function renderForm(req,res,locals){
  res.render('profile', extend({
    title: 'My Profile',
    csrfToken: req.csrfToken(),
    givenName: req.user.givenName,
    surname: req.user.surname,
    streetAddress: req.user.customData.streetAddress,
    city: req.user.customData.city,
    state: req.user.customData.state,
    zip: req.user.customData.zip
  },locals||{}));
}

// Export a function which will create the
// router and return it

module.exports = function profile(){

  var router = express.Router();

  router.use(csurf({ sessionKey: 'stormpathSession' }));

  // Capture all requests, the form library will negotiate
  // between GET and POST requests

  router.all('/', function(req, res) {
    profileForm.handle(req,{
      success: function(form){
        // The form library calls this success method if the
        // form is being POSTED and does not have errors

        // The express-stormpath library will populate req.user,
        // all we have to do is set the properties that we care
        // about and then cal save() on the user object:
        req.user.givenName = form.data.givenName;
        req.user.surname = form.data.surname;
        req.user.customData.streetAddress = form.data.streetAddress;
        req.user.customData.city = form.data.city;
        req.user.customData.state = form.data.state;
        req.user.customData.zip = form.data.zip;
        req.user.customData.save();
        req.user.save(function(err){
          if(err){
            if(err.developerMessage){
              console.error(err);
            }
            renderForm(req,res,{
              errors: [{
                error: err.userMessage ||
                err.message || String(err)
              }]
            });
          }else{
            renderForm(req,res,{
              saved:true
            });
          }
        });
      },
      error: function(form){
        // The form library calls this method if the form
        // has validation errors.  We will collect the errors
        // and render the form again, showing the errors
        // to the user
        renderForm(req,res,{
          errors: collectFormErrors(form)
        });
      },
      empty: function(){
        // The form library calls this method if the
        // method is GET - thus we just need to render
        // the form
        renderForm(req,res);
      }
    });
  });

  // This is an error handler for this router

  router.use(function (err, req, res, next) {
    // This handler catches errors for this router
    if (err.code === 'EBADCSRFTOKEN'){
      // The csurf library is telling us that it can't
      // find a valid token on the form
      if(req.user){
        // session token is invalid or expired.
        // render the form anyways, but tell them what happened
        renderForm(req,res,{
          errors:[{error:'Your form has expired.  Please try again.'}]
        });
      }else{
        // the user's cookies have been deleted, we dont know
        // their intention is - send them back to the home page
        res.redirect('/');
      }
    }else{
      // Let the parent app handle the error
      return next(err);
    }
  });

  return router;
};
Paste this into profile.jade:
html
  head
    title=title
    link(
      href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css',
      rel='stylesheet'
    )
  body
    div.container

      div.page-header
        h1 My Profile

      if errors
        each error in errors
          div.alert.alert-danger
            span #{error.error}
      if saved
        div.alert.alert-success
          span Your profile has been saved
      form.login-form.form-horizontal(method='post', role='form')
        input(name='_csrf', type='hidden', value=csrfToken)

        div.form-group
          label.col-sm-4 First Name
          div.col-sm-8
            input.form-control(
              placeholder='Your first name',
              required=true,
              name='givenName',
              type='text',
              value=givenName)
        div.form-group
          label.col-sm-4 Last Name
          div.col-sm-8
            input.form-control(placeholder='Your last name',
              required=true,
              name='surname',
              type='text',
              value=surname)
        div.form-group
          label.col-sm-4 Street address
          div.col-sm-8
            input.form-control(placeholder='e.g. 123 Sunny Ave',
              required=true,
              name='streetAddress',
              type='text',
              value=streetAddress)
        div.form-group
          label.col-sm-4 City
          div.col-sm-8
            input.form-control(placeholder='e.g. City',
              required=true,
              name='city',
              type='text',
              value=city)
        div.form-group
          label.col-sm-4 State
          div.col-sm-8
            input.form-control(placeholder='e.g. CA',
              required=true,
              name='state',
              type='text',
              value=state)
        div.form-group
          label.col-sm-4 ZIP
          div.col-sm-8
            input.form-control(placeholder='e.g. 94116',
              required=true,
              name='zip',
              type='text',
              value=zip)
        div.form-group
          div.col-sm-offset-4.col-sm-8
            button.login.btn.btn-primary(type='submit') Save
        div.pull-right
          a(href="/") Return to home page

Breaking it down

You’ve just created an Express Router. Saywha? I really like how the Express maintainers have described this:
A router is an isolated instance of middleware and routes.
Routers can be thought of as "mini" applications, capable only
of performing middleware and routing functions. Every express
application has a built-in app router.
… saywha?
In my words: Express 4.0 encourages you to break up your app into “mini apps”. This makes everything much easier to understand and maintain. This is what we’ve done with the profile.js file — we’ve created a “mini app” which handles JUST the details associated with the profile page.
Don’t believe me? Read on.

Plug in your profile page

Because we followed the Router pattern, it’s now this simple to add the profile page to your existing app.js file (put it right above the call to app.listen):
app.use('/profile',stormpath.loginRequired,require('./profile')());
Omg. Yes. YES. You’ve just decoupled the implentation of a route from it’s addressing. Holy grail? Almost. Awesome? Most Def. (By the way, you’ve also forced authentication on this route, using Stormpath, nice!)
Restart your sever and visit /profile, you should see the form now:
Node App Home

Breaking it down – for real

Okay, there’s a LOT more to talk about here. So let me cover the important points:
  • The profile.js file is a builder or constructor, so to speak. You have to invoke it as a method in order to get the router out of it. That’s why we have that empty ()after the require('./profile') statement. Why bother? Because with this pattern you can pass in any options that may be required for this router. At the moment we don’t have any, but who knows what the future holds? Doing this give you room to use this router in multiple web apps and factor out any app-specific config.
  • We are using the forms library to create a schema for the profile form. This is a good practice because it separates the way in which we validate from the form from the way in which the form is displayed.
  • We have a renderForm function which is responsible for creating the view modelof the form — this model is passed down to the Jade layer, so that profile.jadehas all the properties it needs for rendering the form. This render function ensures that our template layer doesn’t blow up with missing values
  • We are using the Csurf library to add CSRF tokens to the form as a security measure. This is done automaticaly for the default forms (login, registration, password reset), but because this is a new, custom router, we have to setup those details manually
  • We reach into the Express-Stormpath library to grab our collectFormErrorsfunction, a handy utility for pulling validation errors out of the response we get from the forms library. Note to self: PR that in to forms library!
  • We make use of the loginRequired middleware to ensure that users are logged in before they can use this profile page

Wrapping it up

Alas, we’ve reached the end of this tutorial. You now have a web app that can reigster new users and allow them to provide you with a shipping address, pretty sweet right?
Following the profile example you now have everything you need to start building other pages in your application. As you build those pages, I’m sure you’ll want to take advantage of some other great features, such as:
Those are just a few of my favorites, but there is so much more!
Please read the Express-Stormpath Product Guide for details on how to implement all these amazing features — and don’t hesitate to reach out to us!
WE LOVE WEB APPS and we want your user management experience to be 10x better than you ever imagined.

Tuesday, June 16, 2015

How to enable developer option in android phone

  1. Open Settings> About on your Android phone or tablet.
  2. If you have a Samsung Galaxy S4, Note 8.0, Tab 3  or any other Galaxy device with Android 4.2, open Settings> More tab> About and tap it.
  3. If you have Galaxy Note 3 or any Galaxy device with Android 4.3, go to Galaxy Note 3 from Settings> General> About and tap the Build version 7 times.
  4. Now scroll to Build number and tap it 7  times.
  5. After tapping the Build Number 7 times, you will see a message “You are now a developer!” If you have a Galaxy S4 or any other Samsung Galaxy device with Android 4.2, the message reads as follows- “Developer mode has been enabled

Composite design pattern

Source : https://sourcemaking.com/design_patterns/composite

Composite Design Pattern

Intent

  • Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
  • Recursive composition
  • "Directories contain entries, each of which could be a directory."
  • 1-to-many "has a" up the "is a" hierarchy

Problem

Application needs to manipulate a hierarchical collection of "primitive" and "composite" objects. Processing of a primitive object is handled one way, and processing of a composite object is handled differently. Having to query the "type" of each object before attempting to process it is not desirable.

Discussion

Define an abstract base class (Component) that specifies the behavior that needs to be exercised uniformly across all primitive and composite objects. Subclass the Primitive and Composite classes off of the Component class. Each Composite object "couples" itself only to the abstract type Component as it manages its "children".
Use this pattern whenever you have "composites that contain components, each of which could be a composite".
Child management methods [e.g. addChild()removeChild()] should normally be defined in the Composite class. Unfortunately, the desire to treat Primitives and Composites uniformly requires that these methods be moved to the abstract Component class. See the "Opinions" section below for a discussion of "safety" versus "transparency" issues.

Structure

Composites that contain Components, each of which could be a Composite.
Composite scheme
Menus that contain menu items, each of which could be a menu.
Row-column GUI layout managers that contain widgets, each of which could be a row-column GUI layout manager.
Directories that contain files, each of which could be a directory.
Containers that contain Elements, each of which could be a Container.

Example

The Composite composes objects into tree structures and lets clients treat individual objects and compositions uniformly. Although the example is abstract, arithmetic expressions are Composites. An arithmetic expression consists of an operand, an operator (+ - * /), and another operand. The operand can be a number, or another arithmetic expresssion. Thus, 2 + 3 and (2 + 3) + (4 * 6) are both valid expressions.
Composite example

Check list

  1. Ensure that your problem is about representing "whole-part" hierarchical relationships.
  2. Consider the heuristic, "Containers that contain containees, each of which could be a container." For example, "Assemblies that contain components, each of which could be an assembly." Divide your domain concepts into container classes, and containee classes.
  3. Create a "lowest common denominator" interface that makes your containers and containees interchangeable. It should specify the behavior that needs to be exercised uniformly across all containee and container objects.
  4. All container and containee classes declare an "is a" relationship to the interface.
  5. All container classes declare a one-to-many "has a" relationship to the interface.
  6. Container classes leverage polymorphism to delegate to their containee objects.
  7. Child management methods [e.g. addChild()removeChild()] should normally be defined in the Composite class. Unfortunately, the desire to treat Leaf and Composite objects uniformly may require that these methods be promoted to the abstract Component class. See the Gang of Four for a discussion of these "safety" versus "transparency" trade-offs.

Rules of thumb

  • Composite and Decorator have similar structure diagrams, reflecting the fact that both rely on recursive composition to organize an open-ended number of objects.
  • Composite can be traversed with Iterator. Visitor can apply an operation over a Composite. Composite could use Chain of Responsibility to let components access global properties through their parent. It could also use Decorator to override these properties on parts of the composition. It could use Observer to tie one object structure to another and State to let a component change its behavior as its state changes.
  • Composite can let you compose a Mediator out of smaller pieces through recursive composition.
  • Decorator is designed to let you add responsibilities to objects without subclassing. Composite's focus is not on embellishment but on representation. These intents are distinct but complementary. Consequently, Composite and Decorator are often used in concert.
  • Flyweight is often combined with Composite to implement shared leaf nodes.

Opinions

The whole point of the Composite pattern is that the Composite can be treated atomically, just like a leaf. If you want to provide an Iterator protocol, fine, but I think that is outside the pattern itself. At the heart of this pattern is the ability for a client to perform operations on an object without needing to know that there are many objects inside.
Being able to treat a heterogeneous collection of objects atomically (or transparently) requires that the "child management" interface be defined at the root of the Composite class hierarchy (the abstract Component class). However, this choice costs you safety, because clients may try to do meaningless things like add and remove objects from leaf objects. On the other hand, if you "design for safety", the child management interface is declared in the Composite class, and you lose transparency because leaves and Composites now have different interfaces.
Smalltalk implementations of the Composite pattern usually do not have the interface for managing the components in the Component interface, but in the Composite interface. C++ implementations tend to put it in the Component interface. This is an extremely interesting fact, and one that I often ponder. I can offer theories to explain it, but nobody knows for sure why it is true.
My Component classes do not know that Composites exist. They provide no help for navigating Composites, nor any help for altering the contents of a Composite. This is because I would like the base class (and all its derivatives) to be reusable in contexts that do not require Composites. When given a base class pointer, if I absolutely need to know whether or not it is a Composite, I will use dynamic_cast to figure this out. In those cases where dynamic_cast is too expensive, I will use a Visitor.
Common complaint: "if I push the Composite interface down into the Composite class, how am I going to enumerate (i.e. traverse) a complex structure?" My answer is that when I have behaviors which apply to hierarchies like the one presented in the Composite pattern, I typically use Visitor, so enumeration isn't a problem - the Visitor knows in each case, exactly what kind of object it's dealing with. The Visitor doesn't need every object to provide an enumeration interface.
Composite doesn't force you to treat all Components as Composites. It merely tells you to put all operations that you want to treat "uniformly" in the Component class. If add, remove, and similar operations cannot, or must not, be treated uniformly, then do not put them in the Component base class. Remember, by the way, that each pattern's structure diagram doesn't define the pattern; it merely depicts what in our experience is a common realization thereof. Just because Composite's structure diagram shows child management operations in the Component base class doesn't mean all implementations of the pattern must do the same.

Code examples