Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS Services and Dependencies Writing Your Own Service/Factory

Fareez Ahmed
Fareez Ahmed
12,728 Points

Factories vs Object Oriented JS

Are the two similar/related at all? For some reason after watching this video I'm thinking they might be.

Alex Vanston

In object oriented programming, a factory is an object for creating other objects. Factory is a design pattern, and oop is a programming language model. Take data, process data, output data. I would say yes and no. I would say factory is a design pattern used with object oriented programming? I could be wrong though, someone with more experience may have a better answer.

1 Answer

Dan Johnson
Dan Johnson
40,532 Points

As Jeffrey mentions, The Factory design pattern is for dealing with object creation. It allows for additional logic to be performed when instantiating an object, such as class type or initial state.

Object Oriented Programming is a paradigm, dealing with the overall programmatic structure.

OOP deals with modelling through objects, and the Factory pattern is a way to create those objects.

Factory Method: http://sourcemaking.com/design_patterns/factory_method Abstract Factory: http://sourcemaking.com/design_patterns/abstract_factory

OOP Principles: http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29