Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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